Rails all the way

I ran into the following issue while i was dealing with a multi-model form where a Sport is being saved with associated Events


<%= render(:partial => "event", :collection => @sport.events) %>

This partial is being rendered for collection of events for new/edit Sport

<% new_or_existing = event.new_record? ? 'new' : 'existing' %>
<% prefix = "sport[#{new_or_existing}_event_attributes][]" %>

<% fields_for prefix, event do |e| -%>
 <%= e.time_select("best_time") %>
<% end -%>

Here is the problem:

For new Event, time_select name attribute should be:   sport[new][][best_time(5i)]
but this was being assigned:   sport[new][best_time(5i)]

Following error is thrown when this form is submitted

Status: 500 Internal Server Error
Conflicting types for parameter containers. Expected an instance of Hash but found an instance of Array

For more information regarding this issue you can go through this ticket

After digging into rails code this came into light

# rails/actionpack/lib/action_view/helpers/form_helper.rb:508

if @object_name.sub!(/\[\]$/,"")
  if object…

View original post 124 more words

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s