我使用以下代码:Rails 3.0.3Vhochstein的Fork for Activescaffoldrake 0.9.0ruby 1.9.2
我有一个名为组件的模型,它与类别有belongs_to关系。这是用activescaffold建模的,效果很好。我休息了几个月,现在我又回来了,活跃的我给了一个"ActionController::RoutingError (undefined method ' class_name' for nil:NilClass):"当我试图访问组件模型时出现错误。我认为这是由于关系(belongs_to)。如果我从模型中删除关系,它就能工作。如果我把它加回去,它就失败了!
任何想法?
代码如下:
路线 namespace :admin do
resources :users,:roles,:vendors,:shipping_modes,:order_types,:sizes,
:suppliers,:categories,:sub_categories, :material_types,:colours,
:materials,:styles,:surcharges, :budget_templates, :budget_components do
as_routes
end
结束h2控制器 namespace :admin do
resources :users,:roles,:vendors,:shipping_modes,:order_types,:sizes,
:suppliers,:categories,:sub_categories, :material_types,:colours,
:materials,:styles,:surcharges, :budget_templates, :budget_components do
as_routes
end
class Admin::BudgetComponentsController < ApplicationController
layout 'site_admin'
active_scaffold :budget_component do |config|
config.actions.exclude :delete,:update
config.columns[:category].form_ui = :select
config.create.columns = [:name,:category]
config.list.columns = [:name,:category]
config.show.columns = [:name,:category]
config.show.columns.add_subgroup "Time Details" do |name_group|
name_group.add :created_at,:updated_at
end
config.list.sorting = {:name => 'ASC'}
end
end
class BudgetComponent < ActiveRecord::Base
belongs_to :category
validates_presence_of :name, :category_id
validates_uniqueness_of :name
end
class Admin::BudgetComponentsController < ApplicationController
layout 'site_admin'
active_scaffold :budget_component do |config|
config.actions.exclude :delete,:update
config.columns[:category].form_ui = :select
config.create.columns = [:name,:category]
config.list.columns = [:name,:category]
config.show.columns = [:name,:category]
config.show.columns.add_subgroup "Time Details" do |name_group|
name_group.add :created_at,:updated_at
end
config.list.sorting = {:name => 'ASC'}
end
end
class BudgetComponent < ActiveRecord::Base
belongs_to :category
validates_presence_of :name, :category_id
validates_uniqueness_of :name
end
我也遇到过类似的问题。解决方案是再次添加nil:NilClass
,然后它将工作。