ReportsController中的NameError #show uninitialized constant Report Rails.root:/ vagrant

时间:2015-01-02 21:44:58

标签: ruby-on-rails ruby routes

我目前正在尝试使用rails show.html.haml来获取当前我的页面以呈现模板,但是我得到了这个未初始化的常量错误。我生成了控制器但是我没有生成脚手架,因为我不想使用模型来生成页面。以下是错误

NameError in ReportsController#show uninitialized constant Report  Rails.root: /vagrant

我不确切地知道我做错了什么,但我认为这与路线或我没有创建铁轨预期的东西有关。我正在获得一份未初始化的常量报告。我想我需要定义资源,但似乎没有用,所以我可能没有正确完成,所以它被排除在下面的路由文件中。任何帮助将不胜感激

这是我的路线档案

# Route prefixes use a single letter to allow for vanity urls of two or more characters
Rails.application.routes.draw do
  if defined? Sidekiq
    require 'sidekiq/web'
    authenticate :user, lambda {|u| u.is_admin? } do
      mount Sidekiq::Web, at: '/admin/sidekiq/jobs', as: :sidekiq
    end
  end

  mount RailsAdmin::Engine => '/admin', :as => 'rails_admin' if defined? RailsAdmin

  # Static pages
  match '/error' => 'pages#error', via: [:get, :post], as: 'error_page'
  get '/terms' => 'pages#terms', as: 'terms'
  get '/privacy' => 'pages#privacy', as: 'privacy'

  # OAuth
  oauth_prefix = Rails.application.config.auth.omniauth.path_prefix
  get "#{oauth_prefix}/:provider/callback" => 'users/oauth#create'
  get "#{oauth_prefix}/failure" => 'users/oauth#failure'
  get "#{oauth_prefix}/:provider" => 'users/oauth#passthru', as: 'provider_auth'
  get oauth_prefix => redirect("#{oauth_prefix}/login")

  # Devise
  devise_prefix = Rails.application.config.auth.devise.path_prefix
  devise_for :users, path: devise_prefix,
    controllers: {registrations: 'users/registrations', sessions: 'users/sessions',
      passwords: 'users/passwords', confirmations: 'users/confirmations', unlocks: 'users/unlocks'},
    path_names: {sign_up: 'signup', sign_in: 'login', sign_out: 'logout', home: 'home'}
  devise_scope :user do
    get "#{devise_prefix}/after" => 'users/registrations#after_auth', as: 'user_root'
  end
  get devise_prefix => redirect('/a/signup')

  # User
  resources :users, path: 'u', only: :show do
    resources :authentications, path: 'accounts'
  end
  get '/home' => 'users#show', as: 'user_home'

  get '/reports' => 'reports#show'

  # Dummy preview pages for testing.
  get '/p/test' => 'pages#test', as: 'test'
  get '/p/email' => 'pages#email' if ENV['ALLOW_EMAIL_PREVIEW'].present?

  get 'robots.:format' => 'robots#index'

  root 'pages#home'
end

控制器/ report_controller

class ReportsController < ApplicationController
  load_and_authorize_resource

  def show
    render template: "reports/show"
  end
end

视图/报告/ show.html.haml

%h1
  hello world!

1 个答案:

答案 0 :(得分:1)

class ReportsController < ApplicationController
  load_and_authorize_resource

  def show
    render template: "reports/show"
  end
end

应该是

class ReportsController < ApplicationController
  load_and_authorize_resource :user

  def show
    render template: "reports/show"
  end
end