Let's say i have a model Warehouse
, a model Car
, and a model Dealer
.
model Car
is like:
attr_accessible :make, :year
belongs_to :warehouse
belongs_to :dealer
controller Cars
is like:
def create
car = current_dealer.find(params[:car][:warehouse_id]).cars.new(params[:car])
car.save!
end
the view of Cars#new
is like:
<%= semantic_form_for @car do |f| %>
<%= f.inputs do %>
<%= f.input :warehouse, :include_blank => false %>
<%= f.input :make %>
<%= f.input :year %>
<% end %>
<% end %>
Dealers can choose a warehouse when adding a car, The above code is protected against mass assignments (a.k.a. dealers adding cars to warehouses they don't own), But it raises an exception saying :warehouse_id
cannot be mass assigned, That's because it's brought with the parameters too as params[:car][:warehouse_id]
.
How to get rid of that error without manually assigning attributes? And is that a good method anyways?
P.S. i tried params[:car].delete(:warehouse_id)
but that doesn't look like the right way to do this.