where all is devise’s current_user method is available? Models? Controllers? Views? Helpers?
I have a Question model which belongs to User. So while saving new Question what is the best way to store user_id in Question?
QuestionsController as of now
def create
@question = Question.create(params[:question])
@question.save
render text: "Question created!"
end
From your code, and assuming that you have a
has_manyrelationship, I would say that the best way to create a question for a user would be something like this:Also,
createis already callingsave. If you want to manually call it you should usecurrent_user.questions.build.