Rails3:路由错误未初始化常量 SiteConfiguration

发布于 2024-11-16 01:02:32 字数 1374 浏览 2 评论 0原文

我知道以前曾有人问过这个问题,并且我发现了许多与我的问题类似的问题,但答案似乎都是相同的“拼写错误”,但我一次又一次地查看了我的代码,但无法指出错误/拼写错误,我开始认为它不仅仅是一个拼写错误:这是我的代码,其中包含文件名的准确拼写:

我通过以下迁移创建了表:

015_create_site_configurations.rb

class CreateSiteConfigurations < ActiveRecord::Migration

  def self.up
    create_table "site_configurations" do |t|
      t.column :config_type,    :string
      t.column :value,          :string

    end

  end

  def self.down
    drop_table "site_configurations"
  end
end

控制器对于这个类

ma​​nage_site_configurations_controller.rb

class ManageSiteConfigurationsController < AdminController

  active_scaffold :site_configurations do |config|
    config.columns = [:config_type, :value]
    config.create.columns = [:config_type, :value]
  end

end

由于我将其用于 ActiveScaffold,这里有一个来自 application.rb 的片段

  def self.active_scaffold_controller_for(klass)
    return ManageUsersController if klass == User
    return ManagePagesController if klass == Page
    return ManageSiteConfigurationsController if klass == SiteConfiguration
    return "#{klass}ScaffoldController".constantize rescue super
  end

,这就是我用于路线的内容,

resources :manage_site_configurations do as_routes end

如果有的话我真的很感激有错误的可以指出来..

I know this has been asked before and I have found many questions that are similar to mine but ever where the answer seems to be the same 'a typo', but I've looked at my code time and time again and can't point the error/typo out, I'm beginning to think its more then just a typo: here's my code with exact spellings for file names:

i created the table with the following migration:

015_create_site_configurations.rb

class CreateSiteConfigurations < ActiveRecord::Migration

  def self.up
    create_table "site_configurations" do |t|
      t.column :config_type,    :string
      t.column :value,          :string

    end

  end

  def self.down
    drop_table "site_configurations"
  end
end

Controller for this class

manage_site_configurations_controller.rb

class ManageSiteConfigurationsController < AdminController

  active_scaffold :site_configurations do |config|
    config.columns = [:config_type, :value]
    config.create.columns = [:config_type, :value]
  end

end

Since im using this for ActiveScaffold here's a snippet from application.rb

  def self.active_scaffold_controller_for(klass)
    return ManageUsersController if klass == User
    return ManagePagesController if klass == Page
    return ManageSiteConfigurationsController if klass == SiteConfiguration
    return "#{klass}ScaffoldController".constantize rescue super
  end

and this is what I used for my routes

resources :manage_site_configurations do as_routes end

I'd really appreciate it if some one can point the error out..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

顾挽 2024-11-23 01:02:32

您已经进行了迁移,但是您是否在 app/models/ 中生成了模型,

rails g active_scaffold Model attr1:type attr2:type
rake db:migrate

否则可能应该

active_scaffold :site_configurations do |config|

active_scaffold :site_configuration do |config|

至少在 https://github.com/activescaffold/active_scaffold/wiki/getting-started

active_scaffold :company do |config|
  config.label = "Customers"
  config.columns = [:name, :phone, :company_type, :comments]
  list.columns.exclude :comments
  list.sorting = {:name => 'ASC'}
  columns[:phone].label = "Phone #"
  columns[:phone].description = "(Format: ###-###-####)"
end

You have the migration, but do you have the model in app/models/ generated by

rails g active_scaffold Model attr1:type attr2:type
rake db:migrate

Otherwise it could be that

active_scaffold :site_configurations do |config|

should be

active_scaffold :site_configuration do |config|

At least they don't pluralize ':company' in the example on https://github.com/activescaffold/active_scaffold/wiki/getting-started

active_scaffold :company do |config|
  config.label = "Customers"
  config.columns = [:name, :phone, :company_type, :comments]
  list.columns.exclude :comments
  list.sorting = {:name => 'ASC'}
  columns[:phone].label = "Phone #"
  columns[:phone].description = "(Format: ###-###-####)"
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文