From 3947513155ffed3b49a2cd0e80cd3ef26b551f59 Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Wed, 21 Nov 2007 22:36:50 -0800 Subject: [PATCH] Add searching to Video Signed-off-by: Ira W. Snyder --- app/controllers/video_controller.rb | 9 +++++++++ app/views/video/list.rhtml | 4 ++++ app/views/video/searchbyname.rhtml | 8 ++++++++ app/views/video/searchresults.rhtml | 28 ++++++++++++++++++++++++++++ db/development.sqlite3 | Bin 9216 -> 9216 bytes 5 files changed, 49 insertions(+) create mode 100644 app/views/video/searchbyname.rhtml create mode 100644 app/views/video/searchresults.rhtml 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 58750cdfa908a401eb1f3b71854d0a81fea384c6..166de3977c625026765e59abe4a549fbcb0db2d1 100644 GIT binary patch delta 71 zcmZqhXz-XI&A4`>%w&E>mdP9VL-<&kvl*D5G9O}I#@xl6y|FNoSw@zXi$PqGpOKM~ bfgvn2B{e@NHATUtC^0=hFKu(XaHRkM#a|Pz delta 40 wcmZqhXz-XI&A4i#%w&E>=E)oQLwH!2yBL_CG9O}I#@w~Bu!?zemvET?00$oo^#A|> -- 2.25.1