ActionController :: RoutingError - 未初始化的常量照片

时间:2016-04-08 06:20:21

标签: ruby-on-rails

我不能不明白,为什么错误路线?

我的路线:

devise_for :users
  get 'documents/delete'

  resources :freelancers
  resources :projects
  resources :documents
  resources :photos

  namespace :photo do
    resources :avatars, only: :destroy
  end

  get 'tags/:skill', to: 'projects#index', as: :skill

  root 'projects#index'

avatars_controller.rb

class Photos::AvatarsController < ApplicationController

  before_action :set_photo


  def delete

  end

  def destroy
    binding.pry
    @photo.avatar = File.new('public/images/default/avatar.png')
     respond_to do |format|
        format.js
      end
  end

  protected

  def set_photo
    @photo = Photo.find(params[:id])
  end
end

当我在控制台中单击链接<%= link_to "Remove", photo_avatar_path(@photo.id), remote: true, method: :delete %>显示错误时: ActionController :: RoutingError - 未初始化的常量照片

1 个答案:

答案 0 :(得分:1)

你的avatars_controller内容:

class Photos::AvatarsController < ApplicationController

应为Photo

class Photo::AvatarsController < ApplicationController

因为在namespace中,photo不是photos

您在上面发布的路线:

namespace :photo do
  resources :avatars, only: :destroy
end