![](/img/trans.png)
[英]Log a user into their subdomain after registration with Rails and Devise
[英]create an instance after devise user registration, rails
在用戶通過設計注冊后,我想自動創建不相關的模型實例,只是想知道我將在哪里以及如何去做?
就像是
@fan.subscriptions.create(band_id: 1)
成功注冊后(用戶為粉絲)
訂閱模式
create_table "subscriptions", id: :serial, force: :cascade do |t|
t.integer "fan_id"
t.boolean "special", default: false
t.integer "band_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "confirmed"
t.index ["band_id"], name: "index_subscriptions_on_band_id"
t.index ["fan_id"], name: "index_subscriptions_on_fan_id"
end
您可以在fan
模型中使用回調,例如:
after_create :subscribe
如果您有一對多的關系:
def subscribe
subscriptions.where(band_id: band_id).first_or_create
end
希望能幫助到你..
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.