我正在尝试在views页面中名为map的文件夹中的新页面(index.html.erb)上显示当前用户的tag_id和检测日期时间。 我有称为检测,借用,用户和rfid_tag的表。这些是关系。
用户:
class User < ActiveRecord::Base
has_many :lendings
has_many :rfid_tags, :through => :lendings
end
RfidTag(有一个tag_id):
class RfidTag < ActiveRecord::Base
has_many :detections
has_many :sensors, :through => :lendings
has_many :users, :through => :lendings
end
贷款:
class Lending < ActiveRecord::Base
belongs_to :rfid_tag
belongs_to :user
end
检测(具有日期时间):
class Detection < ActiveRecord::Base
belongs_to :sensor
belongs_to :rfid_tag
end
我该怎么做?
答案 0 :(得分:1)
您应该获得用户
的tag_id @user.rfid_tags.map(&:tag_id)
或者
@user.rfid_tags.pluck(:tag_id)