私はDeviseとDeviseInvitableを使ってアプリケーションの認証を管理していますが、InvitationsController#updateにAJAXサポートを追加する際に問題があります。 DeviseInvitableのコントローラは次のようになります。これがうまくときresource.errors.empty? == true
を動作し、我々は実行「respond_with_navigational」はどのように機能しますか?
# invitations_controller.rb
# PUT /resource/invitation
def update
self.resource = resource_class.accept_invitation!(params[resource_name])
if resource.errors.empty?
set_flash_message :notice, :updated
sign_in(resource_name, resource)
respond_with resource, :location => after_accept_path_for(resource)
else
respond_with_navigational(resource){ render_with_scope :edit }
end
end
:
respond_with resource, :location => after_accept_path_for(resource)
(すなわち、招待状/ update.js.erbがレンダリングされると、私のjavascriptのコールが行われました)。問題は、そのときresource.errors.empty? == false
であり、我々は実行します。
respond_with_navigational(resource){ render_with_scope :edit }
サーバーは言う:
Rendered invitations/update.js.erb (1.4ms)
が、私のjavascriptの呼び出しは実行されません。 respond_with_navigational
さんはしていることを説明できますか?私は何時間もグーグルで遊んでいましたが、どこにでもこのapiの説明が見つかりませんでした。
ありがとうございます!
この回答のためにここに来た:http://stackoverflow.com/a/9154096/18706(誰でもそれを使用する実用的な例を探している場合)。 – mahemoff
また、これはデフォルトイニシャライザの説明です:https://gist.github.com/3824340 – mahemoff