So far in my app, I have an admin page and a project page. What I want for my admin page is a form, with a *select_tag*, that displays all existing projects. Upon开发者_运维问答 submitting the form, it will direct the user to "projects/#", calling the selected projects "show" function.
<h1> Admin Page </h1>
<br/><br/>
<%= form_tag( WHAT?, :method =>"put") do %>
<%= select_tag(:select_project, options_from_collection_for_select(Project.all, :id,:name), :size=>10) %>
<%= submit_tag("Show Project") %>
<% end %>
I've been trying to figure out what to put in WHAT?. I'm also fairly certain I need to change a controller somewhere. Any input would be helpful
Thanks SP
<%= form_for :project do |form| %>
<%= form.select :id, Project.all.collect{|x|[x.name,x.id]} %><br/>
<%= form.submit "Show Project"
<% end %>
And in your controller
unless params[:project].nil?
@project = Project.find(params[:project][:id])
end
精彩评论