2011-09-20 54 views
0

我正在将一个php应用程序移植到rails中,并且在复杂的表单中遇到问题。我有一个名为menu_headers的acts_as_tree模型,并且希望创建一个能够在单个页面上编辑菜单的窗体。一个菜单可以有不限数量的menu_headers。Rails 3.1 acts_as_tree,表单和值在单个页面上编辑菜单

我在edit.html.erb:这个作品

#this text field works 
<%=text_field :menu_header, :name, :index=>@menu_header.id %> 
<% if @menu_header.children.empty? %> 
     <div>no submenus</div> 
<% else %> 
    <ul> 
    <%= render :partial => 'menu_header_form', :collection => @menu_header.children %> 
    </ul> 
<% end %> 

,然后在_menu_header_form.html.erb在名称是否正确,如menu_header [3] [名],但该值不正确 - 它是上一节中名称的值。问题在于,我如何(可以?)将输入标记的名称从值中分离出来?也许通过一个选项?

# this is text field is problematic one; want to get menu_header_form.name into the 
# value attribute of the tag 
<%=text_field "menu_header", :name, :index=>menu_header_form.id %> 
<% if menu_header_form.children.empty? %> 
    <div>no submenus</div> 
<% else %> 
    <ul><%= render :partial => 'menu_header_form', :collection => menu_header_form.children %> 
    there are submenus 
</ul> 
<% end %> 

如何在上面的text_field中指定正确的值?

THX

回答

0

可以用该值作为像这样的选项更新: <%= text_field:menu_header,:姓名,:指数=> menu_header_form.id,:值=> menu_header_form.name%>

其中修复了在控制器中声明的menu_header问题。