I have been following Railscasts episodes of Nested forms and complex forms. During the time of creating multiple model in a single form I was able to edit, update, delete and create records for sample models that were nested in the Batch model.
I have been breaking my head from a long time and tried searching around as well but could not get any right solution for solving this problem.
my development log file gives me the following error.
ERROR MESSAGE:
Status: 500 Internal Server Error
expected Hash (got Array) for param `samples'
in my controller I have the update action like this
def update
@batch = Batch.find(params[:id])
respond_to do |format|
if @batch.update_attributes(params[:batch])
flash[:notice] = 'Successfully updated Batch.'
format.html { redirect_to(@batch) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @batch.errors, :status => :unprocessable_entity }
end
end
end
my view is something like this:
<%= form_for @batch do |f| %>
......
<%= f.fields_for :samples do |s_form| %>
.... s_form things
<% end %>
<% end %>
my model contains the same stuff :
has_many :samples, :dependent => :destroy
accepts_nested_attributes_for :samples, :reject_if => lambda { |a| a[:content].blank? }, :allow_destroy => true
All suggestions are appreciated.
text_field_tag
in my form because I supplied Rails-2-style args when I was running Rails 3. Do you see yourself doing that at all? If not, can you provide the entirety of your view? (maybe on pastie.org) – Parasiticide