I have two models: List
and Item
. While adding items, I need to get list_id
:
Here is my code:
In items_controler.rb
def new
@item = Item.new
end
In app/models/item.rb
class Item < ActiveRecord::Base
belongs_to :list
attr_accessible :list_id
end
And this is my form:
<%= form_for(@item, remote: true, :html => { :role => "form" }) do |f| %>
<div id="error_explanation" class="bg-danger text-danger"></div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<%= f.label :name, :class => "control-label" %>
<%= f.text_field :name, :class => "form-control first_input" %>
</div>
<div class="form-group">
<%= f.label :color, :class => "control-label" %>
<%= f.text_field :color, :class => "form-control" %>
</div>
<div class="form-group">
<%= f.radio_button :priority, 'top', :checked => true %>
<%= label :priority_top, 'Place at the top of the list' %><br/>
<%= f.radio_button :priority, 'bottom' %>
<%= label :priority_bottom, 'Place at the bottom of the list' %>
<%= f.hidden_field :list_id, :value => params[:list_id] %>
</div>
<div class="form-group">
<%= f.submit @item.new_record? ? "Create Item" : "Update Item", :class => "btn btn-primary" %>
</div>
</div>
</div>
<% end %>
Now em getting the error on page load
undefined method `attr_accessible' for #<Class:0xb3a2f928>
Is there any different way to do this?