Im running into a small (newbie) problem.
I've got 2 models: question & reviews.
Reviews schema: question_id, user_id, rating, comments
On the 'show' view, i've integrated the following form (formtastic):
- semantic_form_for @question.reviews.build do |f|
= f.error_messages
= f.input :rating
= f.input :comments
= f.buttons
My reviews controller's create action looks like this:
def create
@review = Review.new(params[:review])
@review.user_id = current_user.id
if @review.save
flash[:notice] = "Successfully created review."
redirect_to(@review.question)
else
redirect_to(@review.question)
end
end
However, now it simply doesnt seem to save the question id in the question_id field. It does save the user_id nicely.
Does anyone have a clue of what Im doing wrong? If you need logs, let me know! Thanks in advance
you need to add a hidden field for the question id on your form. something like
f.hidden_field :question_id
To be more specific, user_id is saved because you're assigning it in the controller. You need to pass in the question_id from the form to the controller for it to be saved as well.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.