开发者

Rails 3.1 acts_as_tree, form and values to edit a menu on a single page

I'm porting a php app to rails and am开发者_StackOverflow中文版 having trouble with a complex form. I have a acts_as_tree model called menu_headers and would like to create a form that is able to edit a menu on a single page. A menu could have an unlimited number of menu_headers.

I have in edit.html.erb: this works

#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 %>

and then in _menu_header_form.html.erb where the name is correct such as menu_header[3][name] but the value is incorrect - it is the value of name in the previous section. The issue is how do I (can I?) decouple the name of the input tag from the value? Perhaps via an options?

# 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 %>

How would I specify the correct value in the text_field above?

thx


Could update with the value as an option like this: <%=text_field :menu_header, :name, :index=>menu_header_form.id, :value=>menu_header_form.name %>

which fixed the issue of the menu_header declared in the controller from being seen.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜