Devise を使用してアプリケーションにユーザーをログインさせる次の、かなり単純なコードがあります。これは、XHR ではなく HTML リクエストを使用して実行された場合、実際には問題なく機能します。こうするとXHRができて、
= form_for(@user, :url => session_path(@user), :remote => true) do |f|
= f.label :email
= f.text_field :email, :size => 15, :maxlength => 32
= f.label :password
= f.password_field :password, :size => 15, :maxlength => 32
%br
= f.submit "Sign in"
結果は次のとおりです。
Started GET "/" for 127.0.0.1 at 2012-12-04 13:24:44 -0800
Processing by HomeController#index as HTML
Rendered home/_hello_page.html.haml (0.1ms)
Rendered home/index.html.haml within layouts/application (1.9ms)
Completed 200 OK in 18ms (Views: 16.3ms | ActiveRecord: 0.4ms)
Started POST "/users/sign_in" for 127.0.0.1 at 2012-12-04 13:24:54 -0800
Processing by Devise::SessionsController#create as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"1cGaycA20NMhK0fOwQyN8e3aSFwCHB6BZcLwmvKTI3U=", "user"=>{"email"=>"obscured@someplace.com", "password"=>"[FILTERED]"}, "commit"=>"Sign in"}
Completed 500 Internal Server Error in 65ms
ActionView::MissingTemplate (Missing template devise/sessions/create, devise/create, application/create with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :coffee, :haml]}. Searched in:
* "/Users/sxross/Developer/iPhoneApps/motion/whos_here/whos_here_server/app/views"
* "/Users/sxross/.rvm/gems/ruby-1.9.3-p327@whos_here_server/gems/devise-2.1.2/app/views"
):
すべてが私が期待したとおりでありProcessing by Devise::SessionsController#create as JS
、受信コントローラーに「必要な JSON を返送してください」と伝えていることは明らかです。問題は、Devise コントローラーが JSON ではなくテンプレートをレンダリングしようとする理由と、それを修正するために何ができるかということです。
ありがとう!