activescafold owns_to 关系给出路由错误

发布于 2024-12-05 20:45:04 字数 1452 浏览 0 评论 0原文

我正在使用以下内容: 导轨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 技术交流群。

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

发布评论

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

评论(1

念三年u 2024-12-12 20:45:04

我有类似的问题。解决方案是再次添加您的nil:NilClass,然后它就可以工作了。

I had a similar problem. The solution is to add your nil:NilClass again, then it will work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文