元のコードは次のようになります。
def create
self.resource = resource_class.invite!(resource_params, current_inviter)
if resource.errors.empty?
set_flash_message :notice, :send_instructions, :email => self.resource.email
respond_with resource, :location => after_invite_path_for(resource)
else
respond_with_navigational(resource) { render :new }
end
end
このコントローラーでメンバーを作成するときに、メンバーに関連付けられたいくつかのオブジェクトを作成できるように、いくつかの fields_for を招待フォームに追加しようとしています。次のようなものを追加することで、明示的に行うことができます
resource.my_associations.build(params[:my_association])
ビルドステートメントを一般化する方法はありますか? おそらく、params からクラス名を暗示して、その名前を事前に知らずに関連付けを構築しますか?