親子のモデルのビューヘルパー
親子のモデルのビューヘルパー (例:Mother -> Sister)
6人目のMotherからSisterを作るときに悩んだ。
at config/route.rb
map.resources :mothers, :has_one => :sisters
at app/views/mothers/index.html.erb
<%= link_to 'New mother', new_mother_path %> <%= link_to 'Edit', edit_mother_path(mother) %> <%= link_to 'Make Sister', new_mother_sisters_path(mother) %>
at app/models/mother.rb
class Mother < ActiveRecord::Base has_one :sister end
at app/models/sister.rb
class Sister < ActiveRecord::Base belongs_to :mother end