繁体   English   中英

ReportsController#show中的NameError未初始化的常量Report Rails.root:/ vagrant

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

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

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

我不确切知道我在做什么错,但是我认为这与路线有关,或者我没有创建Rails期望的东西。 我收到一个未初始化的常量报告。 我认为我需要定义资源,但是似乎没有用,所以我可能没有正确执行,因此在下面的路由文件中将其排除。 任何帮助将不胜感激

这是我的路线文件

# 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!
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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM