【问题标题】:rails_admin ArgumentError when trying to edit or create a new entry尝试编辑或创建新条目时出现 rails_admin ArgumentError
【发布时间】:2017-05-05 12:53:32
【问题描述】:

我在尝试创建新限制或编辑限制(以下模型)时遇到此错误

Rails_admin/main#new 中的参数错误

显示 /Users/deini/.rvm/gems/ruby-2.0.0-p195/gems/rails_admin-0.4.9/app/views/rails_admin/main/_form_filtering_select.html.haml 其中第 11 行提出:

参数数量错误(0 表示 1+)

提取的源代码(第 11 行附近):(selected_id = field.selected_id)

    selected_id = selected.send(field.associated_primary_key)
     selected_name = selected.send(field.associated_object_label_method)
   else
     selected_id = field.selected_id
     selected_name = field.formatted_value
   end

系统.rb

class System < ActiveRecord::Base
  has_many :attachments

  has_many :limitations
  has_many :companies, :through => :limitations

  accepts_nested_attributes_for :attachments
  accepts_nested_attributes_for :companies

  attr_accessible :conf_type, :version, :hardware_type, :name, :attachments_attributes, :company_ids, :companies_attributes

  rails_admin do
    list do
      exclude_fields :created_at, :updated_at
    end
  end

end

公司.rb

  class Company < ActiveRecord::Base
  belongs_to :distributor
  has_many :users, dependent: :destroy

  has_many :limitations
  has_many :systems, :through => :limitations

  accepts_nested_attributes_for :limitations

  attr_accessible :distributor_id, :name, :system_ids, :email, :limitations_attributes

  rails_admin do
    list do
      exclude_fields :custom_url, :created_at, :updated_at
    end

    edit do
      exclude_fields :custom_url, :users
    end
  end

end

limitation.rb

class Limitation < ActiveRecord::Base
  belongs_to :company
  belongs_to :system
  attr_accessible :company_id, :system_id, :version_limit
end

我没有修改我的 rails_admin 中的任何内容,对我做错了什么有任何想法吗?

【问题讨论】:

  • selected_id 方法的签名是什么?
  • 很抱歉,您所说的 selected_id 方法的签名是什么意思,我怎样才能得到它?
  • 行 'selected_id = field.selected_id' 将局部变量设置为在对象 'field' 上调用方法 'selected_id' 时返回的值。错误说你没有足够的参数 {wrong number of arguments (0 for 1+)} 所以我想知道 selected_id 方法需要什么参数。

标签: ruby-on-rails rails-admin


【解决方案1】:

其实我也遇到了同样的错误。但是当我在整个代码中将名称 System 更改为其他名称时,包括模型、表名等,我的代码开始正常工作。尝试用其他单词更改名称System

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-05
    • 1970-01-01
    • 2017-08-30
    • 2021-11-18
    • 1970-01-01
    • 2011-08-25
    • 1970-01-01
    相关资源
    最近更新 更多