polymorphic_path という Rails メソッドを使用しようとしていますが、間違った URL を取得しています。私のポリモーフィックな関連付けは、userable を通じて User である Student と Landlords との関係です。
ここに私のモデルがあります:
class User < ActiveRecord::Base
belongs_to :userable, polymorphic: true
end
class Student < ActiveRecord::Base
has_one :user, :as => :userable
end
class Landlord < ActiveRecord::Base
has_one :user, :as => :userable
end
User オブジェクトを保持する current_user という変数があります。次の行:
<%= link_to "Profile", polymorphic_path(current_user) %>
学生/家主のURLを返す代わりに、「users/22」というURLを返します。
それが役立つ場合、これが私のroutes.rbファイルです..
resources :users
resources :students
resources :landlords
どこが間違っていますか?ありがとう!