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
<table>
<tr>
+ <th>Video ID</th>
+ <th>Checked Out</th>
<% for column in Video.content_columns %>
<th><%= column.human_name %></th>
<% end %>
<% 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 %>
--- /dev/null
+<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 />
--- /dev/null
+<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 %>