Tôi có một trường hợp đơn giản, liên quan đến hai lớp mô hình:(Object không hỗ trợ #inspect)
class Game < ActiveRecord::Base
has_many :snapshots
def initialize(params={})
# ...
end
end
class Snapshot < ActiveRecord::Base
belongs_to :game
def initialize(params={})
# ...
end
end
với những cuộc di cư:
class CreateGames < ActiveRecord::Migration
def change
create_table :games do |t|
t.string :name
t.string :difficulty
t.string :status
t.timestamps
end
end
end
class CreateSnapshots < ActiveRecord::Migration
def change
create_table :snapshots do |t|
t.integer :game_id
t.integer :branch_mark
t.string :previous_state
t.integer :new_row
t.integer :new_column
t.integer :new_value
t.timestamps
end
end
end
Nếu tôi cố gắng để tạo ra một trường hợp Snapshot ở ray giao diện điều khiển, sử dụng
Snapshot.new
tôi nhận được
(Object doesn't support #inspect)
Bây giờ là phần tốt. Nếu tôi nhận xét phương thức khởi tạo trong snapshot.rb, thì Snapshot.new hoạt động. Tại sao chuyện này đang xảy ra?
BTW Tôi đang sử dụng Rails 3.1 và Ruby 1.9.2
Mặc dù nó có thể không phải là vấn đề của bạn, điều này xuất hiện khi có lỗi trong phương thức 'kiểm tra' tùy chỉnh. Lỗi ban đầu không hiển thị, điều này có thể gây phiền toái. –