Ruby on Rails
Thursday, September 26, 2019
I agree I can clean up the build but the problem I am having is in the form, not the models...
I need to structure the nested form and I can't seem to figure out the rails syntax...
Just experimenting, and currently, this is the closest I have gotten to what I am trying to do...
<% @dd_detail.dd_detail_categories.each do |category| %>
<div class="lunch_order_list_class"><%= category.title.titleize %></div>
<%= f.fields_for :dd_detail_items do |item| %>
<%= item.label :title %>
<%= item.check_box :item_check %>
<%= item.text_field :item_value %>
<%= item.text_area :note %>
<br/>
<%= item.fields_for :dd_detail_subitems do |subitem| %>
<%= subitem.label :title %>
<%= subitem.check_box :item_check %>
<%= subitem.text_field :item_value %>
<%= subitem.text_area :note %>
<br/>
<% end %>
<% end %>
<%= f.fields_for :dd_detail_subcategories do |subcategory| %>
<%= subcategory.label :title %><br/>
<%= subcategory.fields_for :dd_detail_items do |item| %>
<%= item.label :title %>
<%= item.check_box :item_check %>
<%= item.text_field :item_value %>
<%= item.text_area :note %>
<br/>
<%= item.fields_for :dd_detail_subitems do |subitem| %>
<%= subitem.label :title %>
<%= subitem.check_box :item_check %>
<%= subitem.text_field :item_value %>
<%= subitem.text_area :note %>
<br/>
<% end %>
<% end %>
<% end %>
<% end %>
On Thursday, September 26, 2019 at 4:25:03 PM UTC-4, Ariel Juodziukynas wrote:
I'm not sure I understand what's the problem, where exactly do you have doubts?I'd suggest you first refactor that super ugly nested loops and ifs:- remove the unnecesarry if'sDdCategory.all.each do |category|# If the Category is active, build itif category.is_active?can't you handle that is_active? with a scope?- the blocks for category.dd_items and subcategory.dd_items looks almost the same, I think you can reuse some code there- move complex logic to other methods to clean that up, like:item.dd_subitems.each do |subitem|newitem.dd_detail_subitems.create!(dd_detail_item_id: new item.id , title: subitem.title, has_check: subitem.has_check, has_value: subitem.has_value, has_note: subitem.has_note, item_check: subitem.item_check, item_value: subitem.item_value, item_note: subitem.item_note)endcould be a method on newitem like "add_subitem_from(subitem)" that does that create but you'll have less clutter to simplify your logic to understand it betterEl jue., 26 sept. 2019 a las 16:01, John Sanderbeck (<band...@gmail.com>) escribió:Another thing to note is I am also only doing an Edit of the data as the records already have been created and are not allowed to be destroyed.John--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonra...@googlegroups.com .
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ .56b5ef26-e7ed-45a8-b346- b39c45edca0f%40googlegroups. com
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/424ef245-ea1a-410e-89ca-797bec4712f2%40googlegroups.com.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment