I have a rails 4 app.
I have a profiles model and an organisation model.
The associations are:
profile.rb:
belongs_to :organisation organisation.rb
has_many :profiles Then in my show page in my profiles folder, I have:
<% unless @profile.organisation.title.empty? %> <%= @profile.organisation.title %> <% end %> When I try this, I get a no method error:
undefined method `title' for nil:NilClass I don't understand this error. If there is no title, then there is nothing to display.
Can anyone see what I've done wrong?
Taking Miles' suggestion below, I tried changing my profiles show page to:
<% unless Organisation.find(@profile.organisation_id).title.empty? %> <%= Organisation.find(@profile.organisation_id).title %> <% end %> But, I get this error:
Couldn't find Organisation with 'id'= The line starting with 'unless' is highlighted in the error message