首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rails not find -Rails

Rails not find -Rails
EN

Stack Overflow用户
提问于 2020-03-22 09:26:57
回答 2查看 42关注 0票数 0
代码语言:javascript
复制
Rails 3.2

在我的controllers/admin/accounts_receivables_contoller.rb,中,我有:

代码语言:javascript
复制
class Admin::AccountsReceivables < Admin::ApplicationController

  def index
    ...
  end

在其中一种观点中,我有:

代码语言:javascript
复制
= link_to admin_accounts_receivables_path

在我的config/routes.rb中,我有:

代码语言:javascript
复制
namespace :admin do
  resources :accounts_receivables do
    collection do
      get 'admin_report'
      get 'customer_report'
      post 'process_invoices'
    end
  end
end

rake路由,产生:

代码语言:javascript
复制
admin_accounts_receivables GET admin/accounts_receivables(.:format) admin/accounts_receivables#index

但是,当我单击该链接时,我得到(在浏览器中,但在日志文件中没有条目):

代码语言:javascript
复制
uninitialized constant Admin::AccountsReceivablesController

我没有对应的AccountsReceivable模型,因为我不需要它。

有什么想法吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-04-18 08:13:48

该类应该命名为AccountsReceivablesController,并且您应该显式地嵌套该类,而不是使用作用域解析操作符,以便它具有正确的模块嵌套:

代码语言:javascript
复制
module Admin
  class AccountsReceivablesController < ApplicationController
    def index
      #  ...
    end
  end
end

当您使用作用域解析操作符class Admin::AccountsReceivablesController时-模块嵌套被解析到定义点Main (全局作用域)而不是Admin。例如:

代码语言:javascript
复制
module Admin
  FOO = "this is what we expected"
end

FOO = "but this is what we will actually get"

class Admin::AccountsReceivablesController < Admin::ApplicationController
  def index
    render plain: FOO
  end
end

参见The Ruby Style Guide - namespaces

票数 1
EN

Stack Overflow用户

发布于 2020-03-22 10:21:12

代码语言:javascript
复制
class Admin::AccountsReceivables < Admin::ApplicationController

应该是...

代码语言:javascript
复制
class Admin::AccountsReceivablesController < Admin::ApplicationController
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60795063

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档