我正在修改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