0

我可能很愚蠢,但是:

@activation_token = ActivationToken.where(:token => params[:id])
render(:text => @activation_token.inspect)

工作,并给出:

[#<ActivationToken id: 7, user_id: 21, token: "f4c3cb7c7629344e8261bf16e4a99900", used: false, created_at: "2013-01-25 10:48:57", updated_at: "2013-01-25 10:48:57">]

@activation_token.user_id

抛出:

undefined method `user_id' for #<ActiveRecord::Relation:0x007fbfe414ff18>

我错过了什么?

4

1 回答 1

1

尝试:

@activation_token.first.user_id

它提供对象集合,如果您想访问@activation_token.user_id,请使用:

@activation_token = ActivationToken.where(:token => params[:id]).first
# or
@activation_token = ActivationToken.find_by_token(params[:id])
于 2013-01-25T11:26:19.683 回答