Rails3 +不显眼的 JavaScript +移动 - 有人让它工作吗?
我有一个简单的 Rails 项目,它使用不显眼的 Javavscript 进行 ajax 链接/表单处理。一切在桌面上都运行良好。
现在,我正在尝试使该网站移动化。我的理解是,这涉及以下步骤:
启用ApplicationController将
request.format
更改为:mobile
。通常这是通过一个过滤器来完成的,该过滤器读取传入的请求属性并可能设置request.format = :mobile
:before_filter:调整_format_for_mobile
向 mime_types.rb 添加一些行:
Mime::Type.register_alias "text/html", :mobile Mime::Type.register_alias "text/javascript", :mobilejs
向
format.mobile
respond_to 块添加一些新行 和format.mobilejs
respond_to do |格式| 格式.js 格式.mobilejs format.html {redirect_to @post } format.json { 渲染 json: @post } 结尾
我已尝试过以各种方式完成所有这些。我尝试在控制器内“手动”执行#1,然后尝试了 mobile-fu。我在#2 中尝试了各种东西,比如“application/javascript
”。我还尝试了执行 #3 的各种方法(例如显式渲染)。
我可以让应用程序执行除处理来自移动浏览器的 ajax 调用之外的所有操作。它要么找不到合适的模板,要么将模板呈现为 text/html
而不是 Javascript。
我已经了解了用于移动检测的 Railscast (#199),以及这里的一些问题/答案(可能看起来有点过时)。我无法让这个工作。
所以我的问题是:有人能够做到这一点吗?如果可以的话,你能提供一个简单的1、2、3来说明如何做到这一点吗?我认为问题在于文档在不引人注目的 javascript + 移动问题上很薄弱,并且过去有效的各种东西在 Rails 3 中不再有效(也许)?在这一点上,我愿意做几乎任何事情(例如主要的重新配置)来使其正常工作。如果需要的话,我什至愿意放弃不引人注目的 JavaScript 位并以“非轨道”方式做事。
谢谢
I have a simple rails project which makes use of unobtrusive Javavscript for ajax link/form processing. Everything works great on the desktop.
Now, I'm trying to make the site mobile. My understanding is that this involves the following steps:
Enabling the ApplicationController to change the
request.format
to:mobile
. Normally this is done with a filter which reads the incoming request properties and maybe setsrequest.format = :mobile
:before_filter :adjust_format_for_mobile
Adding some lines to mime_types.rb:
Mime::Type.register_alias "text/html", :mobile Mime::Type.register_alias "text/javascript", :mobilejs
Adding some new lines to the
respond_to
blocks forformat.mobile
, andformat.mobilejs
respond_to do |format| format.js format.mobilejs format.html { redirect_to @post } format.json { render json: @post } end
I've tried to do all of these in various ways. I tried doing #1 "by hand" inside the controller, then tried mobile-fu. I tried various things in #2 like "application/javascript
". I also tried various ways of doing #3 (e.g. explicit render).
I can get the application to do everything except process an ajax call from a mobile browser. It will either not find the appropriate template, or render the template as text/html
rather than Javascript.
I've been through the Railscast for mobile detection (#199), as well as a number of questions/answers here (which seem a little outdated maybe). I can't get this working.
So my question: has anyone been able to make this work? If so can you offer a simple 1,2,3 for how to do it? I think the problem is that the documentation is thin on the unobtrusive javascript + mobile issue, and various things that have worked in the past are no longer working in rails 3 (maybe)? At this point I'm willing to do almost anything (e.g. major reconfiguring) to get this working. I'm even willing to dump the unobtrusive javascript bit and do things in a "non-rails" way if I need to.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论