开发者

Trouble creating relationships using omniauth in rails 3

Alright so this is another try at asking my question. I did rather poorly the first time. I have a relationship set up in my models so that users have many submissions and submissions belong to a user. I have a reference column in my submissions table that references :user and an index:

add_index :submissions, :user_id

I am using omniau开发者_高级运维th so that people can sign in with twitter. I simply want to be able to have a signed-in user be able to submit a submission and then have rails understand that there is a relationship between the current_user and the submissions they just wrote. Problem is I can't seem to store current_user in an instance variable like so:

@user = current_user

which I would like to use in my submissions controller (create) like so:

@user = current_user
@submission = @user.submissions.create(params[:submission])

I need this so that I could have a user create a submission on views/submissions/index.html.rb page and rails would understand the relation. Thank you so much for looking at this. Also I apologize in advance if I just missed something really obvious or that is common knowledge.


Your post does not really contain a question or did I miss something? What seems strange to me is that you want to assign @user = current_user. There is no need to do so, current_user should be a user anyway, therefore you could just write @submission = current_user.submissions.create(params[:submission]).

Maybe you can edit your post and provide more details on your helper methods (current_user), the error message you get with the code above. What do you get if you add Rails.logger.info current_user (or current_user.name if you have this field)?

If you want you can follow the link in my profile here on Stack Overflow, I have a couple of Rails tutorials there, including one with Omniauth.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜