通过jQuery Mobile登录Devise

sch*_*der 5 mobile jquery devise ruby-on-rails-3

我们有一个使用Devise进行身份验证的工作应用程序(电子邮件,密码).

要添加移动界面我们正在使用jQuery mobile - 一切正常,除了通过Devise登录不会表现.

点击"登录"后,Rails会正确处理请求,但我们得到的只是一个MissingTemplate(设计/会话/创建)错误.


当前设置:

config.http_authenticatable_on_hxr = false

config.navigational_formats = [:"*/*", "*/*", :html, :mobile]
Run Code Online (Sandbox Code Playgroud)

我们受到Railscast#199(因此:mobile)的启发:http://railscasts.com/episodes/199-mobile-devices

小智 7

尝试本指南的最后一步操作方法:使Devise可以使用其他格式,如移动设备,iphone和ipad(特定于Rails).

请记住使用:to_mobile而不是:to_ios,所以:

ActionController::Responder.class_eval do
  alias :to_mobile :to_html
end
Run Code Online (Sandbox Code Playgroud)

在config/initializers中的新初始化文件中


csc*_*sch 2

覆盖设计的SessionsController作品。我从github获取了控制器的代码,并添加了针对移动设备的redirect_to:

app/controllers/sessions_controller.rb:

class SessionsController < Devise::SessionsController
  def create
    resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
    set_flash_message(:notice, :signed_in) if is_navigational_format?
    sign_in(resource_name, resource)
    if mobile_device?
      redirect_to wherever_you_want
    else
      respond_with resource, :location => redirect_location(resource_name, resource)
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

并在routes.rb

devise_for :users, :path => '/', :controllers => { :sessions => "sessions" }
Run Code Online (Sandbox Code Playgroud)

不要忘记创建app/views/sessions/模板。