ruby on rails - Extra record showing in ActiveRecord query result -
so here's problem:
i have page want list of 'items' displayed. want have form on page used adding additional 'items'.
the 'new' action in controller looks this:
def new @collection = current_user.collections.find_by_id(params[:collection_id]) @item_list = @collection.items @item = @collection.items.new end
the code in view this:
<div class="row-fluid"> <div id="main_area" class="col-sm-offset-3 col-sm-6 col-md-offset-4 col-md-4"> <div class="center"> <h3><%= @collection.title %></h3> <% if @item_list.any? %> <ul> <% @item_list.each |il| %> <li> <%=i l.name %> <% end %> </ul> <% end %> <div id="add_item"> <%=f orm_for [@collection, @item] |f| %> <div class="form-group <%= 'has-error has-feedback' if @item.errors[:name].present? %>"> <label class="sr-only" for="item_name">item name</label> <%=f .text_field :name, :autofocus=>true, :placeholder => "item name", :class => "form-control", :'aria-describedby' => "itemnameblock" %> <% if @collection.errors[:title].present? %> <span id="itemnameblock" class="error">item <%= @item.errors[:name].first %></span> <% end %> </div> <div id="signin_button_row"> <%=f .submit "save", :class=>"form-control green_button" %> <span id="forgot_my_password" class="right-justify"> <%= link_to "cancel", collection_items_path(@collection), :class => "new_colors terms" %> </span> </div> <% end %> </div> </div> </div> </div>
my problem fact loop in view seems have 1 'item' in it, , seems related fact i'm using 'new' in controller.
how around problem?
this create same item not add collection
def new @collection = current_user.collections.find_by_id(params[:collection_id]) @item_list = @collection.items @item = item.new collection_id: @collection.id end
Comments
Post a Comment