我正在修改Rails的MobileFu插件(https://github.com/brendanlim/mobile-fu)以接受是否打开插件的参数。将变量传递给Rails控制器方法
在控制器,你可以调用类似:
class ApplicationController < ActionController::Base
has_mobile_fu
end
但我想这样做:
class ApplicationController < ActionController::Base
has_mobile_fu :mobile_enabled
def mobile_enabled
current_account.mobile_enabled?
end
end
凡current_account由一个子集查找。问题是,当我通过:mobile
时,它只传递符号,而不是:mobile
的值。
下面是相关MobileFu代码:
这是我的编辑:
def has_mobile_fu(enabled, options = {})
include ActionController::MobileFu::InstanceMethods
logger.info "Enabled is: " + enabled.to_s
before_filter(options) do |controller|
controller.set_mobile_format(enabled)
end
helper_method :is_mobile_device?
helper_method :in_mobile_view?
helper_method :is_device?
end
如果我把这个与控制器的静态参数(即has_mobile_fu(false)
),它工作正常。这是当我试图传入一个变量(即has_mobile_fu :mobile_enabled
)时,我遇到了麻烦。变量只是进来作为一个符号(所以上述记录器输出将Enabled is: mobile_enabled
。
谢谢!
ideaoforder - 记得投票和/或接受帮助或解决您的问题的解决方案。这样人们在将来也会更有可能帮助你。谢谢! – Casper