I'm attempting to create an Edit action with form_with in Rails.... My other CRUD actions are working ok, so something to do with my form_with...
<%= form_with(model: [@game, @review], local:true) do |form| %>
this is the tag im attempting to create, yet when I do i get this error
undefined method `review_path' for #<#<Class:0x00007fedfa8befd0>:0x00007fedfa8bd298>
Did you mean? view_paths
directing me back to the tag, this is my controller
def new
@game = Game.find(params[:game_id])
@review = current_user.reviews.new
end
# GET /reviews/1/edit
def edit
end
# POST /reviews
# POST /reviews.json
def create
@review = current_user.reviews.new(review_params)
@game = Game.find(params[:game_id])
@review.game_id = @game.id
respond_to do |format|
if @review.save
format.html { redirect_to game_reviews_path(@review), notice: 'Review was successfully created.' }
format.json { render :show, status: :created, location: @review }
else
format.html { render :new }
format.json { render json: @review.errors, status: :unprocessable_entity }
end
end
end
# <%= link_to "New Review", new_game_review_path(game_id: @game.id) %>
# PATCH/PUT /reviews/1
# PATCH/PUT /reviews/1.json
def update
@review = current_user.reviews.update(review_params)
@game = Game.find(params[:game_id])
@review.game_id = @game.id
respond_to do |format|
if @review.update(review_params)
format.html { redirect_to @review, notice: 'Review was successfully updated.' }
format.json { render :show, status: :ok, location: @review }
else
format.html { render :edit }
format.json { render json: @review.errors, status: :unprocessable_entity }
end
end
end
# DELETE /reviews/1
# DELETE /reviews/1.json
def destroy
@review.destroy
respond_to do |format|
format.html { redirect_to game_reviews_path(@review), notice: 'Review was successfully destroyed.' }
format.json { head :no_content }
end
end
def correct_user
@review = current_user.reviews.find_by(id: params[:id])
redirect_to reviews_path, notice:" Not Authorized to Edit This Review" if @review.nil?
end
Still pretty new to Rails, any help would be great!
Thanks
Aucun commentaire:
Enregistrer un commentaire