ActionController :: UrlGenerationError没有路由匹配

时间:2015-01-03 07:29:31

标签: ruby-on-rails routes

我对rails很新,但似乎无法掌握这条路线

show.html.erb

<%= link_to "up", vote_movie_review_path(@review, type: "up"), method: "post" %>

佣金路线

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

1 个答案:

答案 0 :(得分:1)

您正在使用嵌套路线,因此您还需要传递电影对象。请使用此vote_movie_review_path(@movies, @review, type: "up")

检查您的路线,它显示/movies/:movie_id/reviews/:id/vote,而您调用它的方式将生成类似/reviews/id的方法发布,并且您没有定义任何路线。