From: Ira W. Snyder Date: Thu, 22 Nov 2007 06:36:50 +0000 (-0800) Subject: Add searching to Video X-Git-Tag: turned-in~69 X-Git-Url: https://www.irasnyder.com/gitweb/?a=commitdiff_plain;h=3947513155ffed3b49a2cd0e80cd3ef26b551f59;p=cs356-p2-videostore.git Add searching to Video Signed-off-by: Ira W. Snyder --- diff --git a/app/controllers/video_controller.rb b/app/controllers/video_controller.rb index a5508ae..bf283ef 100644 --- a/app/controllers/video_controller.rb +++ b/app/controllers/video_controller.rb @@ -48,4 +48,13 @@ class VideoController < ApplicationController Video.find(params[:id]).destroy redirect_to :action => 'list' end + + def searchbyname + render :action => 'searchbyname' + end + + def searchresults + query = params[:q] + @videos = Video.find(:all, :conditions => ["title = ?", query]) + end end diff --git a/app/views/video/list.rhtml b/app/views/video/list.rhtml index b981202..1a0ec16 100644 --- a/app/views/video/list.rhtml +++ b/app/views/video/list.rhtml @@ -2,6 +2,8 @@ + + <% for column in Video.content_columns %> <% end %> @@ -9,6 +11,8 @@ <% for video in @videos %> + + <% for column in Video.content_columns %> <% end %> diff --git a/app/views/video/searchbyname.rhtml b/app/views/video/searchbyname.rhtml new file mode 100644 index 0000000..01e85d7 --- /dev/null +++ b/app/views/video/searchbyname.rhtml @@ -0,0 +1,8 @@ +

Search for a Video by Name

+ +<%= start_form_tag :action => 'searchresults'%> +<%= text_field 'q', nil %> + <%= submit_tag 'Search' %> +<%= end_form_tag %> + +
diff --git a/app/views/video/searchresults.rhtml b/app/views/video/searchresults.rhtml new file mode 100644 index 0000000..daefca0 --- /dev/null +++ b/app/views/video/searchresults.rhtml @@ -0,0 +1,28 @@ +

Search Results

+ +<% if @videos.empty? %> +

Sorry, there were no results

+<% else %> +
Video IDChecked Out<%= column.human_name %>
<%=h video.id %><%=h video.checkedout? %><%=h video.send(column.name) %>
+ + + + <% for column in Video.content_columns %> + + <% end %> + + +<% for video in @videos %> + + + + <% for column in Video.content_columns %> + + <% end %> + + + + +<% end %> +
Video IDChecked Out<%= column.human_name %>
<%=h video.id %><%=h video.checkedout? %><%=h video.send(column.name) %><%= link_to 'Show', :action => 'show', :id => video %><%= link_to 'Edit', :action => 'edit', :id => video %><%= link_to 'Destroy', { :action => 'destroy', :id => video }, :confirm => 'Are you sure?', :post => true %>
+<% end %> diff --git a/db/development.sqlite3 b/db/development.sqlite3 index 58750cd..166de39 100644 Binary files a/db/development.sqlite3 and b/db/development.sqlite3 differ