Reputation: 73
I am still very much new to rails, but cant seem to get a grasp on this route
show.html.erb
<%= link_to "up", vote_movie_review_path(@review, type: "up"), method: "post" %>
rake route
vote_movie_review POST /movies/:movie_id/reviews/:id/vote(.:format) reviews#vote
routes.rb
Rails.application.routes.draw do
devise_for :users
resources :movies do
resources :reviews do
member { post :vote }
end
end
reviews_controller.rb
class ReviewsController < ApplicationController
before_action :set_reviews, only: [:show, :edit, :update, :destroy]
before_action :set_movie
before_action :authenticate_user!
respond_to :html
def index
@reviews = Review.all
respond_with(@reviews)
end
def show
end
def vote
value - params[:type] == "up" ? 1 : -1
@review = Review.find(params[:id])
@review.add_evaluation(:votes, value, current_user)
redirect_to :back, notice: "thanks for the vote"
end
Upvotes: 1
Views: 1458
Reputation: 998
You are using nested routes, so you need to pass movie object also.use like this vote_movie_review_path(@movies, @review, type: "up")
.
Check your routes, it showing /movies/:movie_id/reviews/:id/vote
while the way you are calling it will generate like /reviews/id
with method post and for it you have not defined any routes.
Upvotes: 1