I currently have a create action in a sales controller that looks like this:
def create @sale = Sale.new(params[:sale].except(:vehicles_attributes)) if @sale.save redirect_to @sale, :notice => "Successfully created sale." else render :action => 'new' end end
The goal is to exclude a couple of attributes that are only used to populate related samples and should not be sent (there are no columns for them).
With the controller code above, I found that the parameters still contain "sale"=>{"vehicles_attributes"=>{"0"=>{"make"=>"","model"=>""}}} , so it seems that I missed something in the controller code.
EDIT: after some additional searching, I found that the mass_assignment exception was thrown before my code, except for the code, was able to remove the parameters that should not be submitted by the form, so I will go back to the square.
How can I make sure that I delete fields that should not be submitted by the form before I get the mass_assignment error?
source share