从另一个表获取会话ID

时间:2011-03-31 07:21:42

标签: ruby-on-rails

我有3个表 - 答案,问题和代币。

IN tokens我有id, token, created_at, updated_at

IN answers我有id, token (id), text, created_at, updated_at

questions - id, text

如何获取ID(来自令牌)?我这样做:

result=Answer.create(:question_id=>question.id,:token=>session[:token],:text=>params["answer_"+question.id.to_s])

我不想session[:token],它粘贴在表格TOKENS(例如23709274092107hdjshdsj)和我

  

只需要ID!

1 个答案:

答案 0 :(得分:0)

看起来你只是在会话中存储令牌。所以你必须从令牌中获取ID:

token = Token.find_by_token(session[:token])
result=Answer.create(:question_id=>question.id,:token=>token.id,:text=>params["answer_"+question.id.to_s])