私は、その動作をカスタマイズしようとするときにdeviseがどのように動作するのかを理解するのに苦労しています。DeviseはSTIモデルでのみ動作しますか?
私が処理するために、2つの異なるモデルがあります:社会とコラボレーターをし、登録フォームには、それらの両方のための同じビューにしておく必要があります。
したがって、「登録コントローラを作成する」デバイスをオーバーライドして、両方のモデルを処理する新しいコントローラを作成する必要があります。
ここに痛みがあります。 「Devise form within a different controller」とhereここから
、私は工夫が動作するために、それらの新しいヘルパーを定義する必要があることを知っている:
module ContentHelper
def resource_name
:user
end
def resource
@resource ||= User.new
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end
end
そして、私はオーバーライドしたい作成方法はこれです:
def create
build_resource
if resource.save
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
expire_session_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
respond_with resource
end
end
保護者機能を損なうことなく動作させる方法を理解できません。 (build_resource)。なにか提案を? STIを使用して解決策を見つけることができません!