当我运行我的Rails应用程序时,我收到以下错误,"未初始化的常量Blog :: PostsController"
的routes.rb
Rails.application.routes.draw do
devise_for :authors
root to: 'blog/posts#index'
namespace :author do
resources :posts
end
scope module: 'blog' do
get 'about' => 'pages#about', as: :about
get 'contact' => 'pages#contact', as: :contact
get 'posts' => 'posts#index', as: :posts
get 'posts/:id' => 'posts#show', as: :post
end
end
posts.controller.rb
module Blog
class PostsController < BlogController
def index
@post = Post.most_recent
end
def show
@post = Post.friendly.find(params[:id])
end
private
def set_post
end
end
end
目录路径如下:
app/controller/blog/posts.controller.rb
答案 0 :(得分:0)
我猜问题是在命名约定中。 以下是命名约定的示例:
Controller Naming Convention
Class: PostsController
File: /app/controllers/posts_controller.rb
有关命名惯例的更多详细信息,请查看:http://www.ganeshkunwar.com.np/2018/01/02/naming-convention-rails/
还从application_controller继承post控制器,而不是从blog控制器继承。