Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Error: "can't convert nil into Hash" for muliple record updates #262

Closed
wherebear opened this Issue Jan 26, 2012 · 7 comments

Comments

Projects
None yet
2 participants

I have an error that arises when this gem is installed on the form below:

Error:

TypeError in Hours#edit

can't convert nil into Hash

Extracted source (around line #6):

3: <%= form_for :hour, :url => {:action => 'update'}, :validate => false, :method => :put do -%>
4:  <% @hours.each do |hour| %>
5:      <div class="hour_entry_wrap">
6:      <h4 class="day"><%= day_to_text(hour.day) %>: <span class="span_range_<%=hour.day%>"><%= hour_to_time(hour.open) %> to <%= hour_to_time(hour.close) %></span></h4>
7:      <%= fields_for "hours[]", hour do |f| %>
8:          <%= render 'shared/error_messages', :object => f.object %>
9:          <%= f.hidden_field :open, :id => "open_range_"+hour.day.to_s %>

It has to do with the "fields_for" block and the way it is structured. This is the way that a railscast tutorial demonstrated for multiple record updating, and it works perfectly until I installed this gem. I really want to use this gem for validating other forms, I don't want to validate this form with it, which is why I put false in the form but it still gives me the error.

I have tried just about everything, including pulling :validate => false in the fields_for which gives another error. Any help would be greatly appreciated!

Thanks,
Louis

Ignore the weird spacing at line 6, the error is because of line 7. There is also an underscore in the form_for, I don't know why it is making everything italics and formatting it like that.

Contributor

bcardarella commented Jan 26, 2012

Can you gist your form template?

gisted

Contributor

bcardarella commented Jan 27, 2012

Thank-you. I'll take a look at this soon,

Any help would be greatly appreciated

Contributor

bcardarella commented Jul 21, 2012

So I have pushed a fix for not failing when not using :validate => true in 17c43bb

The gem will now raise an error if a Symbol or String is passed for the object with form_for. The reason is because ClientSideValidations needs to build the validation hash from an ActiveRecord object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment