开发者

Form redirect in Ruby on Rails

开发者 https://www.devze.com 2023-03-04 05:50 出处:网络
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, i

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
0

精彩评论

暂无评论...
验证码 换一张
取 消