我正在尝试为我的预订制作多态模型。
预约可以是从USER到ROOM,也可以是从USER到MENU。
这些是我的课程和迁移。
class Room < ActiveRecord::Base
belongs_to :user
has_many :reservations, as: reservable
class Menu < ActiveRecord::Base
belongs_to :user
has_many :reservations, as: reservable
class Reservation < ActiveRecord::Base
belongs_to :user
belongs_to :reservable, polymorphic: true
end
在我的控制器中,我试图通过以下方式访问我的预订:
def your_trips
@trips = current_user.reservations
end
但是我收到了错误:
NameError in PagesController#home
undefined local variable or method `reservable' for # <Class:0x000000054c8308> Did you mean? reset_table_name
Extracted source (around line #4):
Rails.root: /home/ubuntu/workspace
Application Trace | Framework Trace | Full Trace
app/models/room.rb:4:in `<class:Room>'
app/models/room.rb:1:in `<top (required)>'
app/controllers/pages_controller.rb:3:in `home'
有没有人有想法的原因?