ruby-on-rails - 带有 JQTouch 登录问题的 iPhone 上的 Rails

标签 ruby-on-rails http jqtouch

我有一个使用 jqtouch 的带有移动 View 的 Rails 应用程序。如果在 iPhone 上查看应用程序,则加载 application.mobile.erb 代替默认的 application.HTML.erb。

一切正常,除了登录。用户可以登录然后查看内容。但是,他们每次加载网站时都必须登录。有没有办法让 iPhone 将凭据存储为 cookie 或类似的东西?

我注意到,如果我在 iPhone 上查看桌面版本并登录,我的登录凭据会被存储,因此我不必每次都登录。一旦我切换到 iPhone 特定的 jqtouch 版本,我每次都必须登录。

不同之处在于,在桌面版本上,我将登录详细信息直接输入到我制作的登录表单中,但在 iPhone jqtouch 版本上,iPhone UI 的弹出窗口要求登录信息。

应用程序使用 Restful 身份验证插件:http://github.com/technoweenie/restful-authentication

谢谢,

丹尼

可以在github上查看应用:

www.github.com/dannyweb/baseapp2

最佳答案

免责声明:我对 RoR 还很陌生,所以这是我最好的猜测,可能完全不对...

我注意到在你的 app/views/dashboard 中你有 index.html.erbindex.mobile.erb,所以我我假设您正在使用 .mobile 后缀来获取 iPhone 特定的移动页面。在您的 lib/authenticated_system.rb 中,您的拒绝访问方法是:

  def access_denied
      respond_to do |format|
        format.html do
          store_location
          redirect_to new_session_path
        end
        # format.any doesn't work in rails version < http://dev.rubyonrails.org/changeset/8987
        # you may want to change format.any to e.g. format.any(:js, :xml)
        format.any do
          request_http_basic_authentication 'Web Password'
        end
      end
    end

每当未经授权的用户试图访问内容时都会调用此方法(请参阅您的 authorized 方法以查看什么使用户有资格获得授权)。此方法根据请求的格式响应请求.. 即任何 .html 请求命中 format.html do block 。由于没有 format.mobile block ,所有 .mobile 请求最终都会到达 format.any block 。这会导致您在问题中解释的行为:

The difference is that on the desktop version I enter the login details directly into the login form I made, but on the iPhone jqtouch version a popup from the iPhone UI requests the login information.

两者之间的另一个区别是 format.html 创建一个 session ,而 format.any 只请求凭据而不创建 session 。

您是否考虑过添加 format.mobile block 来指定身份验证系统应如何处理 .mobile 请求以便创建 session (类似于 format.html堵塞)?您甚至可以尝试使用相同的 request_http_basic_authentication 方法(以便 iPhone UI 请求凭据),然后对提交的凭据执行某些操作以创建 session 或 cookie。

再说一次,我可能完全没有根据,但希望我的回答能帮上大忙!

关于ruby-on-rails - 带有 JQTouch 登录问题的 iPhone 上的 Rails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3383258/

相关文章:

ruby-on-rails - 主动存储的高响应时间

ruby-on-rails - Gemset:此系统上当前未安装 Rails。

javascript - 基于网络的移动应用程序闪烁问题的根本原因?

javascript - Google Map V3 未居中,仅显示 map 的一部分

javascript - 使用 jQTouch javascript iphone/ipad 的简单滑动画廊

ruby-on-rails - ImageMagickError 无法读取字体 `(null)' : `(null)'

ruby-on-rails - RSPEC - 注释掉 Controller 操作,测试是否仍然通过? Rails 上的 Ruby

angularjs - 是否可以将参数化 URL 模板与 Angular $http 服务一起使用

java - 我们可以使用http代码422(不可处理的实体)进行Get操作吗?

http - 从 golang 中的 reader.io 对象获取属性