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

时间:2011-06-17 08:31:34

标签: ruby-on-rails-3 routes uninitialized-constant

我知道之前已经问过这个问题,我发现了许多类似于我的问题,但答案似乎是“错字”,但我一次又一次地看着我的代码,可以不要指出错误/错字,我开始认为它只是一个错字:这是我的代码,文件名的拼写错误:

我使用以下迁移创建了表:

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

此课程的控制器

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

因为我在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

如果有人可以指出错误,我真的很感激。

1 个答案:

答案 0 :(得分:0)

您有迁移,但是您是否已在

生成的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

的示例中复制':company'
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