Reputation: 12653
If I have the following models:
class Section < ActiveRecord::Base
has_many :pages, :dependent => :destroy
end
class Page < ActiveRecord::Base
belongs_to :section
end
And I had a section owning a page, how could I add a link_to that would link to that pages parent? Or, how could I find a page's owner?
Upvotes: 1
Views: 243
Reputation: 4144
@page = Page.find(params[:id]) # or whatever the criteria
@page_link = link_to "section", @page.section
Or, in the view:
<%= link_to "section", @page.section %>
Upvotes: 5