Take the 2-minute tour ×

I'm Rails newbie so this might be incredibly stupid question but I hope somebody finds the time to help me :)

I'm currently doing my first Rails 3 application with MongoDB. I have setup Devise for authentication and it's working great. I'm trying to create blog type of app so each registered user can post an article. Naturally user model has "many: posts" and post model has "belongs_to: user" but here's the problem: I don't want to have user_id as a field in the new post form for security reasons so how can I pass the current user to post model? I removed all fields related to user data from the form so now it doesn't seem to be able to get the data for user_id anywhere.

So how do I use Devise's current_user helper method to pass the correct user_id to post model for proper association?

share|improve this question

1 Answer 1

I assume you have a controller action responsible for handling your post creation. In RESTful design that would be create action normally. That action would call a save or create method on your model. Prior to the method call, assign the user_id to your devise's @current_user.id.

share|improve this answer

Your Answer


