KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I would like to display a line of text only if an object called @foo is set. In my view, I'm trying something like this: <% if !@foo.new_record? || !@foo.nil? %> Foo is not a new record or nil <% end %> But this fails, returning You have a nil object when you didn't expect it! I'm pretty sure this happens because of the new_record? method. How do I check if something is not a new record or nil without causing an error? In PHP, it would be achieved by asking if(!empty($foo)) but even the empty? method in rails causes the same error to be returned. Any ideas?
Tags (comma-separated)
Save Edits
Cancel