ruby-on-rails - collection_label 的 Simple_form 样式

标签 ruby-on-rails css ruby-on-rails-3 simple-form

我有这个 simple_form

<%= simple_form_for(@order) do |f| %>
                    <%= f.error_notification %>
                    <%= f.association :orderstatus, :label => false, :include_blank => false, :input_html => { :class => 'order-status' } , :as => :radio, :label_html => { :style => "background-color:black;" } %>
                    <%= f.button :submit, :value => 'Update', :class => 'button grey small' %>

                <% end %>

它创建了这个:http://d.pr/9Bqd在数据库中,我还有一个 color 字段,它是我想要的每个状态的背景颜色的十六进制代码。知道如何将这个十六进制代码传递到每个背景标签颜色吗?!我已经尝试了几个小时。

最佳答案

你有没有试过像这样传递它......

 # assuming "hex" is stored in the order model. Any variable should work
 :label_html => { :style => "background-color:##{@order.hex};" }

如果没有,请回复您的结果

关于ruby-on-rails - collection_label 的 Simple_form 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9171226/

相关文章:

ruby-on-rails - Rails 3 - 自定义 link_to 助手(具有默认类和添加类的能力)

ruby-on-rails - React 新功能 : Why is one array treated differently than the other?

javascript - Rails 4 中汉堡包 jquery 按钮代码在哪里?

ruby-on-rails - 嵌入式网络服务器环境中的 Django 或 Ruby on Rails?

ruby-on-rails - 无法从 gem 生成 friendly_id

ruby-on-rails - rails -find_by_sql : wrong number of arguments (2 for 1)

ruby-on-rails - Rails 4 i18n,如何在将子域用作语言环境的地方转换路线

CSS3 变换 - 缩放动画有时会在 Chrome 上回弹

html - 通过悬停另一个 <img> 来更改 <img> 元素

javascript - html 雅虎股票不能在两个 DIV 中工作