我刚刚开始从头开始创建新的应用程序,并从这个控制器调用一个Pocket模型:
class HomeController < ApplicationController
def index
end
def wallets_index
end
def wallets_show
end
def wallets_new
@pocket = Pocket.new
end
end
出现了一个奇怪的错误:
事务由活动记录定义。检查以确保没有具有相同名称的属性或方法。
我的模式:
create_table "pockets", force: :cascade do |t|
t.string "address"
t.bigint "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "transaction"
t.index ["user_id"], name: "index_pockets_on_user_id"
end
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
add_foreign_key "pockets", "users"
和口袋模型:
class Pocket < ApplicationRecord
belongs_to :user
end
这实际上是我第一次遇到这种情况,我不知道应该重命名哪个属性以避免冲突?
您正在Pocket
型号中使用transaction
列
t.integer "transaction"
我建议不要使用与rails方法名称相似的列。transaction
方法在Rails
的transactions.rb模块中定义
但是,如果你真的想使用它,你可以检查safe_attributesgem。
在pockets
表或迁移中,transaction
是一个保留字,因此不能使用该字。