Add searching to Video
authorIra W. Snyder <devel@irasnyder.com>
Thu, 22 Nov 2007 06:36:50 +0000 (22:36 -0800)
committerIra W. Snyder <devel@irasnyder.com>
Thu, 22 Nov 2007 06:36:50 +0000 (22:36 -0800)
Signed-off-by: Ira W. Snyder <devel@irasnyder.com>
app/controllers/video_controller.rb
app/views/video/list.rhtml
app/views/video/searchbyname.rhtml [new file with mode: 0644]
app/views/video/searchresults.rhtml [new file with mode: 0644]
db/development.sqlite3

index a5508ae..bf283ef 100644 (file)
@@ -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
index b981202..1a0ec16 100644 (file)
@@ -2,6 +2,8 @@
 
 <table>
   <tr>
+  <th>Video ID</th>
+  <th>Checked Out</th>
   <% for column in Video.content_columns %>
     <th><%= column.human_name %></th>
   <% end %>
@@ -9,6 +11,8 @@
   
 <% for video in @videos %>
   <tr>
+  <td><%=h video.id %></td>
+  <td><%=h video.checkedout? %></td>
   <% for column in Video.content_columns %>
     <td><%=h video.send(column.name) %></td>
   <% end %>
diff --git a/app/views/video/searchbyname.rhtml b/app/views/video/searchbyname.rhtml
new file mode 100644 (file)
index 0000000..01e85d7
--- /dev/null
@@ -0,0 +1,8 @@
+<h1>Search for a Video by Name</h1>
+
+<%= start_form_tag :action => 'searchresults'%>
+<%= text_field 'q', nil  %>
+  <%= submit_tag 'Search' %></form>
+<%= end_form_tag %>
+
+<br />
diff --git a/app/views/video/searchresults.rhtml b/app/views/video/searchresults.rhtml
new file mode 100644 (file)
index 0000000..daefca0
--- /dev/null
@@ -0,0 +1,28 @@
+<h1>Search Results</h1>
+
+<% if @videos.empty? %>
+<p>Sorry, there were no results</p>
+<% else %>
+<table>
+  <tr>
+  <th>Video ID</th>
+  <th>Checked Out</th>
+  <% for column in Video.content_columns %>
+    <th><%= column.human_name %></th>
+  <% end %>
+  </tr>
+
+<% for video in @videos %>
+  <tr>
+  <td><%=h video.id %></td>
+  <td><%=h video.checkedout? %></td>
+  <% for column in Video.content_columns %>
+    <td><%=h video.send(column.name) %></td>
+  <% end %>
+    <td><%= link_to 'Show', :action => 'show', :id => video %></td>
+    <td><%= link_to 'Edit', :action => 'edit', :id => video %></td>
+    <td><%= link_to 'Destroy', { :action => 'destroy', :id => video }, :confirm => 'Are you sure?', :post => true %></td>
+  </tr>
+<% end %>
+</table>
+<% end %>
index 58750cd..166de39 100644 (file)
Binary files a/db/development.sqlite3 and b/db/development.sqlite3 differ