get session id from another table
I have 3 tables--answers, questions and tokens.
IN tokens
I have id, token, created_at, updated_at
.
IN answers
i have id, token (id), text, created_at, updated_at
In questions
- id, text
How can I get ID (from tokens) ? I do this way:
result=Answer.create(:question_id=>question.id,:token=>session[:token],:text=>params["answer_"+question.id.to_s])
开发者_如何学Go
I don't want session[:token]
, it's pasted in table TOKENS (for example 23709274092107hdjshdsj) and I
just need ID!
It looks as though you're only storing the token in session. So you'd have to get the ID from the token so:
token = Token.find_by_token(session[:token])
result=Answer.create(:question_id=>question.id,:token=>token.id,:text=>params["answer_"+question.id.to_s])
精彩评论