新手问题 render Layout 的提问,不能正确加载

yeyong14 · May 20, 2014 · Last by yeyong14 replied at May 21, 2014 · 2344 hits

因为需要另外创建一个移动版的布局,生成了mobile下的控制器。没有跟原来的在一起

class ApplicationController < ActionController::Base
  has_mobile_fu
 before_filter :mobile
 private
  def mobile
     if is_mobile_device?
        render 'layouts/mobile/application' #这个能加载。但是不能传递<%= yiled %>
        #如果不这样的判断是可以的,这个按需加载样版要怎么样加载的?
     end
    end
end
class Mobile::HomeController < ApplicationController
 layout "layouts/mobile/application"
#这行好像是多余的。在去掉application判断。这个能正常工作
end
class Mobile::ProductsController < Mobile::HomeController
  #这个类的变量不能传递到layouts/mobile/application
  def index
  end
end

#router

namespace :mobile do
  resoures :products
end

你把 Class 方法跟 Instance 方法弄混了。试试:

self.class.layout "layouts/mobile/application"

@lyfi2003 这个加载好像是在products/index ,没能加载到mobile/products/index下的文件

这句话又不是控制你说这一点的

@lyfi2003 不是很明白你的意思,能否给点思路,不胜感激

You need to Sign in before reply, if you don't have an account, please Sign up first.