0
我有以下代碼:創建關係保存相關的ID
class User < ActiveRecord::Base
has_many :campaigns
...
end
class Campaign < ActiveRecord::Base
belongs_to :user
...
end
class CampaignsController < ApplicationController
def create
@campaign = Campaign.new(campaign_params)
@campaign.user_id = @current_user.id
...
end
end
的問題是,有沒有通過導軌爲此提供了一種方法:@[email protected]_user.id
?
是的,你剛剛做到了。這不工作? –
它可以工作,但它似乎並不是正確的導軌方式 – zer0uno