访问用户拥有的对象的属性

时间:2013-12-05 01:33:38

标签: ruby-on-rails ruby ruby-on-rails-4

当我这样做时:

current_user.predictions.inspect

我明白了:

#<Prediction id: 1, home_prediction: 1, away_prediction: 2, first_goalscorer: "Baaaa", double: nil, user_id: 1, match_id: 1, created_at: "2013-12-04 22:48:23", updated_at: "2013-12-04 22:48:23">

但是当我这样做时:

current_user.predictions.match_id

我收到此错误:

undefined method `match_id'

如何访问用户预测的match_id并确保他们尚未进行预测?

谢谢!

1 个答案:

答案 0 :(得分:0)

那里似乎有东西

current_user.predictions是复数,所以它听起来像一个集合

所以试试:

current_user.predictions.first.match_id
相关问题