Ransack: undefined method `name' for nil:NilClass error

Created on 21 Oct 2015  路  3Comments  路  Source: activerecord-hackery/ransack

Just playing around with a simple rails app with only one model that I have scaffolded just for this project.

Inside a search_form_for, I have a <%= f.label :name_cont %> and <%= f.text_field :name_cont%> -- basically as per RailsCasts and the ReadMe.

I get undefined method name' for nil:NilClass error. My model does have a name column and the <%= sort_link(@q, :name, "Name") %> filter works fine.

I run Ruby 2.2.0, Rails 4.2.0, and Ransack 1.7.0.

Any ideas? Thanks.

Most helpful comment

Just noticed that occurs after @search.build_condition call.

E.g.

@search = model.search(params[:q])
@search.name_cont # ok
@search.build_condition
@search.name_cont # raises nil pointer error

All 3 comments

Hi @AnnaErshova, could you please provide the information needed to reproduce your exact issue? Please see the Contributing Guide. So far, it looks more like a bug in your code than with Ransack, but I'll re-open this and have a look when you've given enough info to reproduce it. OK? Thanks :smiley:

@jonatack I did fix it, but I think it was something with Ransack. It went away after I updated command tools I think (that was a while back). Just keep an eye out for it if someone else reports it. Thanks!

Just noticed that occurs after @search.build_condition call.

E.g.

@search = model.search(params[:q])
@search.name_cont # ok
@search.build_condition
@search.name_cont # raises nil pointer error
Was this page helpful?
0 / 5 - 0 ratings

Related issues

seanfcarroll picture seanfcarroll  路  4Comments

grillorafael picture grillorafael  路  5Comments

zenati picture zenati  路  4Comments

ghost picture ghost  路  5Comments

mkalmykov picture mkalmykov  路  3Comments