2011-03-31 66 views
0

我有3個表格 - 答案,問題和標記。我有id, token, created_at, updated_at從另一個表中獲取會話ID

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],它粘貼在表格標記(例如23709274092107hdjshdsj)和我

只需要ID!

回答

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])