My goal is to fill an html table in a view (schedule.html.haml):
- if @plans != nil
%p display this if plans is not null
- if @plans == nil
%p= action_name
with the data from @plans in a controller:
def schedule
@plans = Order.all
end
I am sure Order.all returns data. Route file is:
get 'schedule', to: 'order_articles#schedule'
When I try to do this plans is null. The output is:
schedule
I tried to check if plans is null with the code in the view. What did I do wrong?
@planswould benil. It should always be a (potentially empty) array. So there must be something wrong with how you're calling the controller action/setting the variable, but I don't know what.nilis the singleton instance ofNilClass; checking#nil?is exactly the same thing as checking== nil.nil, see my answer below explained how.