I’ve got a view which looks like this:
<p><%= stage.end_date.strftime("%A, %d %B %Y")%></p>
Sometimes stage.end_date returns null and that’s ok, but Ruby throws a NoMethodError.
I’m quite new to Ruby so I want to know how I should I deal with missing/null varibles in views
- Do I need to test for stage.end_date in the view? because that feels ugly
- Do I need to make sure
that stage.end_date isn’t null, if so
that isn’t a job for my view is it? - Is there a way I can get ruby not
worry out about stage.end_date and
not throw an errow?
Advice most welcome
You can do this a bunch of ways, but here are two:
or in your stage model, create: