activescafold owns_to 关系给出路由错误
我正在使用以下内容: 导轨3.0.3 Vhochstein 的 Activescaffold 叉子 耙子0.9.0 ruby 1.9.2
我有一个名为“组件”的模型,它与类别有“belongs_to”关系。这是使用 activescaffold 进行建模的,并且运行良好。我休息了几个月,现在我又回来了,activescafold 给出了 每当我尝试访问组件模型时,都会出现“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
端
控制器
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
I am using the following:
Rails 3.0.3
Vhochstein's Fork for Activescaffold
rake 0.9.0
ruby 1.9.2
I have a model called component which has a belongs_to relationship with category. This was modelled using activescaffold and was working quite well. I took a break for a couple of months and now that I got back to it activescafold gives a
"ActionController::RoutingError (undefined method `class_name' for nil:NilClass):" error whenever I try to access the component model.
I figured this is due to the relationship (belongs_to). If i remove the relationship from the model, it works. If I add it back it fails!
Any Ideas?
Here is the Code:
Routes
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
end
Controller
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
Model
class BudgetComponent < ActiveRecord::Base
belongs_to :category
validates_presence_of :name, :category_id
validates_uniqueness_of :name
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有类似的问题。解决方案是再次添加您的
nil:NilClass
,然后它就可以工作了。I had a similar problem. The solution is to add your
nil:NilClass
again, then it will work.