如何为 ruby 中的 HAML class 创建条件
How to make make a conditional for a HAML class in ruby
我有一个包含选项卡 A、B 和 C 的页面,每个选项卡都包含 'things' 的列表。当我创建一个新的 'thing' 时,我指定它是列表 A、B 还是 C 的一部分。我希望在保存新的 'thing' 并刷新页面后激活适当的标签.
这是我的标签 HAML
%ul.nav.nav-tabs
%li.active
%a{href:"#a", :"data-toggle" => "tab"}
"A things"
%li
%a{href:"#b", :"data-toggle" => "tab"}
"B things"
%li
%a{href:"#c", :"data-toggle" => "tab"}
"C things"
.tab-content
#a.tab-pane.fade.in.active
"tab data"
#b.tab-pane.fade.in
"tab data"
#c.tab-pane.fade.in
"tab data"
我如何编写 ruby 条件,将 active
class 当前硬编码在 "a" 选项卡上添加数据到?
类似于:
控制器:
class ThingsController < ActionController::Base
def create
@active_tab = *some logic to get the tab*
# create logic
end
end
查看:
%ul.nav.nav-tabs
%li{class: @active_tab.nil? || @active_tab == "A" ? "active : ""}
%a{href:"#a", :"data-toggle" => "tab"}
"A things"
%li{class: @active_tab == "B" ? "active : ""}
%a{href:"#b", :"data-toggle" => "tab"}
"B things"
%li{class: @active_tab == "C" ? "active : ""}
%a{href:"#c", :"data-toggle" => "tab"}
"C things"
.tab-content
%a.tab-pane.fade.in{class: @active_tab.nil? || @active_tab == "A" ? "active : ""}
"tab data"
%b.tab-pane.fade.in{class: @active_tab == "B" ? "active : ""}
"tab data"
%c.tab-pane.fade.in{class: @active_tab == "C" ? "active : ""}
"tab data"
不过使用数组会更好。
我有一个包含选项卡 A、B 和 C 的页面,每个选项卡都包含 'things' 的列表。当我创建一个新的 'thing' 时,我指定它是列表 A、B 还是 C 的一部分。我希望在保存新的 'thing' 并刷新页面后激活适当的标签.
这是我的标签 HAML
%ul.nav.nav-tabs
%li.active
%a{href:"#a", :"data-toggle" => "tab"}
"A things"
%li
%a{href:"#b", :"data-toggle" => "tab"}
"B things"
%li
%a{href:"#c", :"data-toggle" => "tab"}
"C things"
.tab-content
#a.tab-pane.fade.in.active
"tab data"
#b.tab-pane.fade.in
"tab data"
#c.tab-pane.fade.in
"tab data"
我如何编写 ruby 条件,将 active
class 当前硬编码在 "a" 选项卡上添加数据到?
类似于:
控制器:
class ThingsController < ActionController::Base
def create
@active_tab = *some logic to get the tab*
# create logic
end
end
查看:
%ul.nav.nav-tabs
%li{class: @active_tab.nil? || @active_tab == "A" ? "active : ""}
%a{href:"#a", :"data-toggle" => "tab"}
"A things"
%li{class: @active_tab == "B" ? "active : ""}
%a{href:"#b", :"data-toggle" => "tab"}
"B things"
%li{class: @active_tab == "C" ? "active : ""}
%a{href:"#c", :"data-toggle" => "tab"}
"C things"
.tab-content
%a.tab-pane.fade.in{class: @active_tab.nil? || @active_tab == "A" ? "active : ""}
"tab data"
%b.tab-pane.fade.in{class: @active_tab == "B" ? "active : ""}
"tab data"
%c.tab-pane.fade.in{class: @active_tab == "C" ? "active : ""}
"tab data"
不过使用数组会更好。