Ruby on rails 如何使用表单_中的If、else帮助器提取特定字段

Ruby on rails 如何使用表单_中的If、else帮助器提取特定字段,ruby-on-rails,form-for,Ruby On Rails,Form For,我的编辑视图中有以下代码: <%= form_for @content do |f|%> <% if f.text_field :home %> <%= f.label :Home %> <%= f.text_field :home %> <% elsif f.text_field :aboutus %> <%= f.label :Abouts %> <%= f.text_field :

我的编辑视图中有以下代码:

<%= form_for @content do |f|%>
  <% if f.text_field :home %>
    <%= f.label :Home %>
    <%= f.text_field :home %>
  <% elsif f.text_field :aboutus %>
  <%= f.label :Abouts %>
  <%= f.text_field :aboutus %>
 <% end %>
<%= f.submit%>

所以我想,如果有人想编辑主页,他只能看到主页提交表单,如果他选择aboutus,他只能看到关于我们的编辑表单页面。建议我使用什么正确的方法,如果,否则在这个块中?

你可以传递一个URL参数并使用它。例如:

# in some view
<%= link_to "Edit Homepage", edit_content_path(page: "home")
# this will link to /contents/:id/edit?page=home
#在某些视图中

我应该对此编辑内容路径(页面:“主页”)的路由做哪些更改?无需任何更改,只需使用编辑页面的当前URL帮助器即可。您可以将任何想要的参数传递给URL帮助器,即使是您不使用的参数,例如:
edit_content_path(page:“foo”,blablabla:“hi”)
将创建
/contents/:id/edit?page=foo&blablablabla=hi
我得到以下错误:没有与之匹配的路由{:action=>“edit”、:controller=>“contents”、:page=>“home”}
# in some view
<%= link_to "Edit Homepage", edit_content_path(page: "home")
# this will link to /contents/:id/edit?page=home
<%= form_for @content do |f|%>
  <% if params[:page] == "home" %>
    <%= f.label :home %>
    <%= f.text_field :home %>
  <% else %>
    <%= f.label :about_us %>
    <%= f.text_field :about_us %>
 <% end %>
<%= f.submit%>