【问题标题】:Render radio as button/image simple_form将单选渲染为按钮/图像 simple_form
【发布时间】:2012-07-20 16:12:14
【问题描述】:

我正在使用 SimpleForm 并且能够创建收音机列表。有没有办法可以将它们呈现为按钮或图像?

我做了一些搜索并尝试了这个:

- f.collection_radio_buttons(:category, [['Male', 'icon_male'], ['Female', 'icon_female']], :first, :last) do |category|
  = category.label { image_tag("/assets/icons/16x16/#{category.text}.png") + category.radio_button  }

但是,它仍然呈现单选图标,见下文

有没有办法将其呈现为可选择的图像或类似于 Twitter Bootstrap 按钮的按钮? http://twitter.github.com/bootstrap/javascript.html#buttons

另外,这需要我指定视图中的图像列表,我需要将其从模型中移除,例如 category.image_url

【问题讨论】:

  • 您可能会发现this answer 很有趣。不过需要一点 JS。

标签: ruby-on-rails-3 twitter-bootstrap simple-form


【解决方案1】:

我最终没有使用 simple_form 的 radio 元素。我只是求助于 jQuery 和一个隐藏的输入元素。

【讨论】:

    猜你喜欢
    • 2018-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-19
    • 2013-03-06
    • 2017-10-23
    • 1970-01-01
    相关资源
    最近更新 更多