I have a User model and a Profile model.
A User has_one Profile and a Profile belongs_to User.
From within app/views/users/show.html.erb, I would like to display the user's associated profile details.
I created a partial at app/views/profiles/shared/_show.html.erb. It contains:
<p>
<strong>Title:</strong>
<%= @profile.title %>
</p>
I am trying to include this partial from within app/views/users/show.html.erb like so (as recommended in the API documentation):
<%= render partial: 'profiles/shared/show', locals: { profile: @user.profile }%>
However, I keep getting the error:
undefined method `title' for nil:NilClass
If I remove the <%= @profile.title %> line from the partial, it renders correctly (so I assume the path is correct).
I have also checked that @user.profile contains a valid Profile object. It does.
What am I missing? How can I pass a variable to a partial which is shared with another controller?
profile.title