Rails 中的哈希问题
我在名为 a_level: 的方法中使用以下代码,
if(@program.theme==MyHelper::TemplateConstants::DEFAULT_LAYOUT)
style = 'border: none'
elsif(@program.theme == MyHelper::TemplateConstants::LOGO_LAYOUT)
style = 'border: top'
end
中的名为 b_level: 的方法中使用以下代码
if(@program.theme==MyHelper::TemplateConstants::DEFAULT_LAYOUT)
style = 'color: #888;'
elsif(@program.theme == MyHelper::TemplateConstants::LOGO_LAYOUT)
style = 'color: #666;'
并在同一帮助程序 。我想用散列代替,就像
my_styles = { :level_a => {... }, :level_b => {...} }
我没有得到正确的东西。 任何帮助表示赞赏!
Im using the following code within a method called a_level:
if(@program.theme==MyHelper::TemplateConstants::DEFAULT_LAYOUT)
style = 'border: none'
elsif(@program.theme == MyHelper::TemplateConstants::LOGO_LAYOUT)
style = 'border: top'
end
And the following within a method called b_level:
if(@program.theme==MyHelper::TemplateConstants::DEFAULT_LAYOUT)
style = 'color: #888;'
elsif(@program.theme == MyHelper::TemplateConstants::LOGO_LAYOUT)
style = 'color: #666;'
in the same helper. I want to use a hash instead, something like
my_styles = { :level_a => {... }, :level_b => {...} }
Im not getting it right.
Any help is appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

我想你正在寻找这个:
然后在
program_logo
:和
do_not_reply
:或者也许安排你的
style_hash
更有意义像这样:然后像这样访问它:
I think you're looking for this:
and then in
program_logo
:and in
do_not_reply
:Or perhaps it would make more sense to arrange your
style_hash
like this:And then access it like this: