I'm trying to make an app in Rails 4.
I have a profile model, and an organisation model. Organisation has an attribute called 'title'.
Associations are:
Profile belongs_to organisation
Organisations has_many profiles
I'm trying to figure out how to write a link from my profile show page to the organisation show page.
I feel that this is correct:
<%= link_to @profile.organisation.try(:title).upcase, organisation_path(@profile.organisation.id) %>
However, when I try it, I get this error:
undefined method `id' for nil:NilClass
I can see in my console that the profile.organisation id is not nil - it has a value.
Can anyone see what I've done wrong?
rake routes - for organisation:
organisations GET /organisations(.:format) organisations#index
POST /organisations(.:format) organisations#create
new_organisation GET /organisations/new(.:format) organisations#new
edit_organisation GET /organisations/:id/edit(.:format) organisations#edit
organisation GET /organisations/:id(.:format) organisations#show
PATCH /organisations/:id(.:format) organisations#update
PUT /organisations/:id(.:format) organisations#update
DELETE /organisations/:id(.:format) organisations#destroy