简体   繁体   English

Ruby on Rails中的表单重定向

[英]Form redirect in Ruby on Rails

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. 我想要的管理页面是带有* select_tag *的表单,该表单显示所有现有项目。 Upon submitting the form, it will direct the user to "projects/#", calling the selected projects "show" function. 提交表单后,它将引导用户进入“ projects /#”,将所选项目称为“ show”功能。

<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 感谢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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM