Devise를 사용하여 사용자를 내 애플리케이션에 로그인해야하는 다음과 같은 간단한 코드가 있습니다. 이것은 XHR이 아닌 HTML 요청을 사용하면 실제로 잘 작동합니다. 내가 이런 식으로 작업을 수행 할 때 XHR은Devits Ajax를 사용하여 로그인 할 때 401을 반환 할 때
= 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 "https://stackoverflow.com/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"=>"[email protected]", "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/[email protected]_here_server/gems/devise-2.1.2/app/views"
):
모든 것이 정확하게하고 Processing by Devise::SessionsController#create as JS
이 수신 컨트롤러를 말하고있는 것이 분명 내가 원한 JSON을 돌려 준다. " 그래서 문제는 Devise 컨트롤러가 JSON 대신 템플릿을 렌더링하려고하는 이유이며이를 수정하려면 어떻게해야합니까?
감사합니다.
당신은 이것을 보았습니까? http://jessehowarth.com/devise –
예. 나는 그랬다. 그 마법이 무엇인지는 잘 모르겠지만 jQuery.ajax를 적절한 accept-type과 함께 사용했을 때 200 반환 코드를 얻을 수있었습니다. 나는이 사실에 대한 진정한 "대답"이 없기 때문에 대답하지 않을 것이다. 그냥 쉬워야 할 것 같습니다. 그래도 고마워! –