Note that there are some explanatory texts on larger screens.

plurals
  1. POunknown attribute X, but X is not in argument of update_attributes in rails3
    primarykey
    data
    text
    <p>I am trying to set object's field in the form with accept_nested_attributes. However in the controller when I do :</p> <pre><code>@device.update_attributes(params[:device]) </code></pre> <p>I get :</p> <pre><code>ActiveRecord::UnknownAttributeError "unknown attribute: device_id" </code></pre> <p>but device_id, which is an attribute of other non-related model, is not included in params. Params are like following.</p> <pre><code>{"utf8"=&gt;"✓", "authenticity_token"=&gt;"Xja5GCNRutpZn2c4wKeSx0KO6sNEzh09kWmPQ0/0Hys=", "id"=&gt;"5", "device"=&gt;{"routes_attributes"=&gt;{"0"=&gt;{"name"=&gt;"", "origin_attributes"=&gt;{"name"=&gt;"", "lat"=&gt;"", "lng"=&gt;""}, "destination_attributes"=&gt;{"name"=&gt;"", "lat"=&gt;"", "lng"=&gt;""}}}}, "commit"=&gt;"Create Device"} </code></pre> <p>What can be thought as a cause. Here are my codes.</p> <p>view</p> <pre><code>&lt;%= form_for @device, :url =&gt; {:action =&gt; "do_compose"}, :method =&gt; :post do |f| %&gt; &lt;div class="field"&gt; &lt;%= select_tag(:id, options_for_select( Device.all.collect{|d| [d.name + "/" + d.get_driver().name, d.id] } ),:prompt=&gt;"select a device") %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= render partial:"routes/nested_routes_form", locals: {route_object:@device.get_route(), parent_form:f} %&gt; &lt;/div&gt; &lt;div class="actions"&gt; &lt;%= f.submit %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>controller</p> <pre><code> def do_compose @device = Device.find(params[:id]) respond_to do |format| if @device.update_attributes(params[:device]) format.html { redirect_to @device, notice: 'Device was successfully updated.' } else format.html { render action: comopse } end end end </code></pre> <p>model </p> <pre><code> class Route &lt; ActiveRecord::Base attr_accessible :name, :destination_attributes, :origin_attributes, :waypoints, :driver_id has_many :waypoints has_one :origin, :class_name=&gt;"Origin" has_one :destination, :class_name=&gt;"Destination" belongs_to :device accepts_nested_attributes_for :origin, :destination, :waypoints end class Device &lt; ActiveRecord::Base attr_accessible :id, :name, :password attr_accessible :device_driver_bind_attributes, :drivers_attributes, :routes_attributes, :current_location_attributes has_many :drivers, through: :device_driver_bind has_many :device_driver_bind, dependent: :destroy has_one :current_location, :class_name =&gt; "CurrentLocation" has_many :routes has_many :origins, through: :routes has_many :destinations, through: :routes has_many :waypoints, through: :routes accepts_nested_attributes_for :routes, :current_location, :device_driver_bind end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload