ruby on rails 3 - unknown attribute X, but X is not in argument of update_attributes in rails3 -
i trying set object's field in form accept_nested_attributes. in controller when :
@device.update_attributes(params[:device])
i :
activerecord::unknownattributeerror "unknown attribute: device_id"
but device_id, attribute of other non-related model, not included in params. params following.
{"utf8"=>"✓", "authenticity_token"=>"xja5gcnrutpzn2c4wkesx0ko6snezh09kwmpq0/0hys=", "id"=>"5", "device"=>{"routes_attributes"=>{"0"=>{"name"=>"", "origin_attributes"=>{"name"=>"", "lat"=>"", "lng"=>""}, "destination_attributes"=>{"name"=>"", "lat"=>"", "lng"=>""}}}}, "commit"=>"create device"}
what can thought cause. here codes.
view
<%= form_for @device, :url => {:action => "do_compose"}, :method => :post |f| %> <div class="field"> <%= select_tag(:id, options_for_select( device.all.collect{|d| [d.name + "/" + d.get_driver().name, d.id] } ),:prompt=>"select device") %> </div> <div class="field"> <%= render partial:"routes/nested_routes_form", locals: {route_object:@device.get_route(), parent_form:f} %> </div> <div class="actions"> <%= f.submit %> </div> <% end %>
controller
def do_compose @device = device.find(params[:id]) respond_to |format| if @device.update_attributes(params[:device]) format.html { redirect_to @device, notice: 'device updated.' } else format.html { render action: comopse } end end end
model
class route < activerecord::base attr_accessible :name, :destination_attributes, :origin_attributes, :waypoints, :driver_id has_many :waypoints has_one :origin, :class_name=>"origin" has_one :destination, :class_name=>"destination" belongs_to :device accepts_nested_attributes_for :origin, :destination, :waypoints end class device < 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 => "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
this has problem in select_tag, try this:
<%= f.select(:id, options_for_select( device.all.collect{|d| [d.name + "/" + d.get_driver().name, d.id] } ),:prompt=>"select device") %>
Comments
Post a Comment