RailsAdmin :: Main#delete中的Rails Admin NoMethodError

时间:2014-07-10 12:59:37

标签: ruby-on-rails ruby rails-admin

我有型号订单:

class Order < ActiveRecord::Base
  has_one :shipping_address
  has_and_belongs_to_many :books

  validates :first_name, :surename, :email, :street1, :country, :zipcode, presence: true
  validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
  validates :zipcode, numericality: true

  accepts_nested_attributes_for :shipping_address
end

和模型书:

class Book < ActiveRecord::Base

  DEFAULT_PRICE = 55.15
  NEXT_BOOK_PERCENT = 5

  has_and_belongs_to_many :pages
  has_and_belongs_to_many :orders

  validates :name, presence: {message: "Name can't be blank."}
  validates_length_of :name, minimum: 3, maximum: 12, message: "Sorry, we can't create             this book right now. Please contact us for further information."

  validate :same_letter_validation
  validate :validates_for_non_alphabetic


  before_save :compile

  #......
end

我还有table books_orders(book_id,order_id)

当我尝试从RailsAdmin面板删除订单时,我得到下一个错误:

RailsAdmin中的NoMethodError :: Main#delete

未定义的方法`orders_books&#39;对于#

它表示此行中的错误:

- @abstract_model.each_associated_children(object) do |association, child|

2 个答案:

答案 0 :(得分:0)

您是否在代码中的任何位置定义了“orders_books”方法?如果是这样,请将它添加到您的问题中。如果你还没有,那么问题的根本原因就在于你正在调用“orders_books”方法,但它还没有定义

鉴于您在问题中引用了“#books_orders”,我相信您可能只是在代码中的某个位置交换了“books_orders”和“orders_books”

答案 1 :(得分:0)

感谢。这是Rails 4.1.1的错误。我已将其更新到4.1.4并且一切正常。