build with nested forms

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

build with nested forms

fugee ohu
The I'm getting error is
undefined method `item_property_id' for #<ItemItemProperty::ActiveRecord_Associations_CollectionProxy:0x007f82c41438d8>

  def new
        @item = Item.new(item_params)
        ItemProperty.where(item_type: params[:item][:item_type]).each do |ip|
            @item.item_item_properties.build(item_property_id: ip.id)
        end
  end


            <%= f.fields_for :item_item_properties do |iip| %>
                      <div class="item_item_property">
                          <%= iip.label "#{ItemProperty.find(@item.item_item_properties.item_property_id).name}" %>  <%= iip.hidden_field :item_property_id, value: @item.item_item_properties.item_property_id %> <%= iip.text_field  :text_value %>
                      </div>
            <% end %>

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/98eed4a3-d1dc-4a3e-a0af-058d0f10740b%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: build with nested forms

Ariel Juodziukynas
@item.item_item_properties.item_property_id is wrong, @item.item_item_properties is a collection, use `iip.object.item_property.name` and `iip.object.item_property_id` instead.

imagine @item.item_item_properties is something like an array [item_item_property1, item_item_property2], you can't call `item_property_id` on an array, you have to call it on one of the items inside it, and that "iip" variable, if you call `.object` on it you get that item from within the array.

El sáb., 2 nov. 2019 a las 4:38, fugee ohu (<[hidden email]>) escribió:
The I'm getting error is
undefined method `item_property_id' for #<ItemItemProperty::ActiveRecord_Associations_CollectionProxy:0x007f82c41438d8>

  def new
        @item = Item.new(item_params)
        ItemProperty.where(item_type: params[:item][:item_type]).each do |ip|
            @item.item_item_properties.build(item_property_id: ip.id)
        end
  end


            <%= f.fields_for :item_item_properties do |iip| %>
                      <div class="item_item_property">
                          <%= iip.label "#{ItemProperty.find(@item.item_item_properties.item_property_id).name}" %>  <%= iip.hidden_field :item_property_id, value: @item.item_item_properties.item_property_id %> <%= iip.text_field  :text_value %>
                      </div>
            <% end %>

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/98eed4a3-d1dc-4a3e-a0af-058d0f10740b%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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAPS3bcB%2BXNyGzA%3D9sq2rDCc_TVvm3rOdjXoLNuiSxC%3DubH8p3g%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: build with nested forms

Joe Guerra
check out the cocoon gem, it made nested forms really simple.

On Saturday, November 2, 2019 at 9:17:31 AM UTC-4, Ariel Juodziukynas wrote:
@item.item_item_properties.item_property_id is wrong, @item.item_item_properties is a collection, use `<a href="http://iip.object.item_property.name" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fiip.object.item_property.name\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHqYORp1AmrggIDp0pRoxES8ZpR4w&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fiip.object.item_property.name\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHqYORp1AmrggIDp0pRoxES8ZpR4w&#39;;return true;">iip.object.item_property.name` and `iip.object.item_property_id` instead.

imagine @item.item_item_properties is something like an array [item_item_property1, item_item_property2], you can't call `item_property_id` on an array, you have to call it on one of the items inside it, and that "iip" variable, if you call `.object` on it you get that item from within the array.

El sáb., 2 nov. 2019 a las 4:38, fugee ohu (<<a href="javascript:" target="_blank" gdf-obfuscated-mailto="TuWK-vgPBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">fuge...@...>) escribió:
The I'm getting error is
undefined method `item_property_id' for #<ItemItemProperty::ActiveRecord_Associations_CollectionProxy:0x007f82c41438d8>

  def new
        @item = Item.new(item_params)
        ItemProperty.where(item_type: params[:item][:item_type]).each do |ip|
            @item.item_item_properties.build(item_property_id: <a href="http://ip.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fip.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFk5GuIN6iBfNmsDSejiOOUqgCWFA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fip.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFk5GuIN6iBfNmsDSejiOOUqgCWFA&#39;;return true;">ip.id)
        end
  end


            <%= f.fields_for :item_item_properties do |iip| %>
                      <div class="item_item_property">
                          <%= iip.label "#{ItemProperty.find(@item.item_item_properties.item_property_id).name}" %>  <%= iip.hidden_field :item_property_id, value: @item.item_item_properties.item_property_id %> <%= iip.text_field  :text_value %>
                      </div>
            <% end %>

--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="TuWK-vgPBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonra...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-talk/98eed4a3-d1dc-4a3e-a0af-058d0f10740b%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/98eed4a3-d1dc-4a3e-a0af-058d0f10740b%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/98eed4a3-d1dc-4a3e-a0af-058d0f10740b%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-talk/98eed4a3-d1dc-4a3e-a0af-058d0f10740b%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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/7a60a14a-5cf0-403b-9d9c-8136546104eb%40googlegroups.com.