我正在實施「功能開關」,以便管理員可以使用管理Web界面打開和關閉新功能。如何在使用資產管道時爲導軌中的功能開關創建「條件資產」?
我能夠很容易地與這樣如
- if FeatureSwitch.where(name: 'display_demo_feature_switch_image', status: 'on').count > 0
# in reality would refactor that query to the controller/model. put here for clarity.
%br
%br
%div{class: "onoffswitch"}
%input{type: "checkbox", name: "onoffswitch", class: "onoffswitch-checkbox", id: "myonoffswitch"}
%label{class: "onoffswitch-label", for: "myonoffswitch"}
%span{class: "onoffswitch-inner"}
%span{class: "onoffswitch-switch"}
但我怎麼能做到這一點的看法時,我使用的管道資產,使資產是「有條件」包括這樣做的看法?
所以,如果我有一個CSS資產清單(app/assets/stylesheets/application.css
)有:
/*
*= require_self
*= require main
*= require default
*= require on_off_switch
*= require jquery-ui-1.8.22.custom.css
*/
我怎樣才能讓require on_off_switch
「有條件的」,這取決於從
FeatureSwitch
.where(name: 'display_demo_feature_switch_image', status: 'on').count > 0
我真/假返回嘗試重命名爲application.css
至application.css.erb
並使用
<% if 'abc' == 'def' %> # While developing/testing
*= require on_off_switch
<% end %>
但資產始終得到包括儘管'abc' == 'def'
是假的......