Skip to content

Instantly share code, notes, and snippets.

@stefanpenner
Forked from eqdw/gist:133582
Created June 21, 2009 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanpenner/133587 to your computer and use it in GitHub Desktop.
Save stefanpenner/133587 to your computer and use it in GitHub Desktop.
<!--- RENDERED PARTIAL >
<tr>
<td><%=h bug.user.company_name %> </td>
<td>Submitted by <%=h bug.submitter %></td>
<td><%=h bug.subject %> </td>
<td> <%=h truncate(bug.description.gsub(/<.*?>/,''), :length => 80) %> </td>
<td> <%= link_to 'Show', bug %> </td>
<% if session[:admin] %>
<td> <%= link_to 'Edit', edit_bug_path(bug)%> </td>
<td> <%= link_to 'Destroy', bug, :confirm => 'Are you sure?',
:method => :delete %> </td>
<% end %>
</tr>
<!--- THIS IS THE VIEW >
<h1>Index:</h1>
<% form_tag :action => "index" do %>
<fieldset>
<legend>Enter Search Criteria</legend>
<div>
<label for="Company">Company Name:</label>
<%= collection_select( :user, :company_name, User.all,
:company_name, :company_name, options = {:prompt => "-Select a Company"}) %>
</div>
<div>
<label for="Username">Username:</label>
<%= collection_select( :user, :name, User.all, :name, :name,
options = {:prompt => "-Select a Username"}) %>
</div>
<div>
<label for="Submitter">Submitted By:</label>
<%= collection_select( :bug, :submitter, Bug.all, :submitter,
:submitter, options = {:prompt => "-Select a Submitter"}) %>
</div>
<div>
<%= submit_tag "Search" %>
</div>
</fieldset>
<%end%>
</div>
<div id="bug-list">
<% unless @bugs == nil %>
<h1> Listing bugs:</h1>
<table>
<%= render(:partial => "shared/bug", :collection => @bugs) %>
</table>
<%end%>
</div>
# The action
# Thanks, burke!
def index
@bugs = nil
if request.post?
mappings = Hash.new{|k,v|v}
allowed_user_attrib = [:company_name, :name]
allowed_bug_attrib = [:submitter]
user_attrib = params[:user].reject{|k,v| ! allowed_user_attrib.include?(k)}
bug_attrib = params[:bug].reject {|k,v| ! allowed_bug_attrib.include?(k)}
if user_attrib
user = User.find(:first, :conditions => user_attrib)
bug_attrib.merge!({:user_id => user})
end
@bugs = Bug.find(:all, :conditions => bug_attrib)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment