I would like to build a new Review form, but it return me an error than I don't understand. Con you explain me the problem ?
My code
routes :
resources :posts do
resources :pushs do
resources :reviews
end
end
The link :
<%= link_to 'Add comment', new_post_push_review_path(@push.post_id, @push) %>
The form that I would like to built :
<%= simple_form_for([@post, @post.push.reviews.build]) do |f| %>
<%= f.input :rating %>
<%= f.input :comment %>
<%= f.button :submit %>
<% end %>
& finally, the controller review :
class ReviewsController < ApplicationController
before_action :authenticate_user!
before_action :find_push
before_action :find_post
def new
@review = Review.new
@pushs = Push.all
end
def create
@push = Push.find(params[:review][:id])
@review = Review.new(review_params)
@review.post_id = @push.post_id
@review.push_id = @push.id
@review.user_id = current_user.id
if @review.save
redirect_to push_path(@push.post_id, @push)
else
render 'new'
end
end
private
def review_params
params.require(:review).permit(:rating, :comment)
end
def find_post
@post = Post.find(params[:post_id])
end
def find_push
@post = Post.find(params[:post_id])
@push = @post.pushs.find(params[:push_id])
end
end
Well, if you have any ideas to explain me my error(s), that would be great !!
Aucun commentaire:
Enregistrer un commentaire