ruby on rails - Heroku nil class error -



ruby on rails - Heroku nil class error -

i pushed local rails 4 app heroku, , i've got unusual error. case, works fine locally no issues. think heroku db / environment same local (as far know anyway!)

the error in heroku logs is: actionview::template::error (undefined method 'empty?' nil:nilclass)

it's trying tell if association empty or not-- if empty display no results partial-- if it's not empty loop through results , display result partial each.

controller:

@polls = poll.where('team_id = ? , expires_at >= ?', params['id'], datetime.now())

view:

<% if @polls.empty? %> <%= render partial: "noresults" %> <% else %> <% @polls.each |p| %> <%= render partial: "poll", locals: {poll: p} %> <% end %> <% end %>

i opened heroku console , ran @polls query, returned proper association, able test empty? , worked expected.

any thought causing this?

edit:

database.yml

production: adapter: postgresql encoding: unicode pool: 5

data

the issue you've got you're calling .empty? on variable / info object hasn't been set

this standard issue when deploy environment, doesn't have populated info have in development. either caused production db not beingness populated (no records), or don't have production db hooked (unlikely)

to prepare this, you'll either want create sure have polls set, or add together status if statement:

<% if !@polls.present? || @polls.empty? %> <%= render partial: "noresults" %> <% else %> ... <% end %>

cause

the bottom line cause variable not populated, resulting in application beingness unable phone call method need. standard issue rails apps (not ones running on heroku)

to resolve it, need verify object exists. 1 way utilize conditional method outlined above, or utilize .blank? suggested niall

ruby-on-rails postgresql heroku ruby-on-rails-4

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -