1

在 Rails 中,我正在尝试实现移动视图。刚刚安装mobylette的 gem 似乎比 mobile_fu 有更多的活动。

https://github.com/tscolari/mobylette

但是,来自移动设备的大多数请求最终都会出现此错误

ActionView::MissingTemplate: Missing template my_controller/index, application/index with {:locale=>[:en], :formats=>[:mobile], :handlers=>[:erb, :builder, :haml]}. Searched in: * "/app/app/views" * "/app/vendor/bundle/ruby/1.9.1/gems/devise-1.5.2/app/views" * "/app/app/views"

知道为什么吗?

4

2 回答 2

0

您可能需要自己添加移动格式。

在 config/initializers/mime_types.rb 中,添加:

Mime::Type.register_alias "text/html", :mobile
于 2012-05-21T08:21:49.847 回答
0

如果您respond_to :mobile在控制器中设置了 mime 类型,那么您唯一的问题应该是实际上缺少移动模板文件。

默认情况下,您需要在适当的 view_path 中有一个名为的模板文件<action>.<format>.<handler> or <action>.<handler>

我怀疑默认设计模板(成功创建重定向以显示操作后)是show.html.erb

您最安全的选择是创建它或对其进行符号链接(以及所有其他操作)

ln -sf show.html.erb show.mobile.erb # in linux

在哪里?好吧,如果你使用了设计 rake 任务

rails generate devise:views

那么你知道它会在app/views/devise/registrations

如果你在config.scoped_views = true里面设置config/initializers/devise.rb,那么它会在app/views/users/registrations你的设计模型是用户使用用户控制器的情况下。

于 2012-05-21T11:51:10.057 回答