I am learning rails and have run into bump.
I have a view that contains the following:
<span><%= @goals.cost_per_conversion %></span>
(just as an example while @goals actually contains more then just cost_per_conversion)
Under certain circumstances the view will not have the instance variable @goals. I am trying to guard against cases when this is true.
In my controller I have the following code:
if Goal.exists?(params[:id])
@goals = Goal.find(params[:id])
else
@goals.cost_per_conversion = 'N/A'
end
Naturally this returns an error as .conversions is not a method.
How do I set the conversions param so that my view can still work when there is no @goals variable available.