Add Image Tag to Checkbox Input Field with Rails 4 and Simple Form

試著忘記壹切 提交于 2019-12-13 21:00:27

问题


Using Rails 4, Simple_Form and Bootstrap 3, I am trying to get my output HTML look like this to work with some front end styling:

<div class="checkbox">
  <input value="0" type="hidden" name="member[remember_me]">
    <label class="boolean optional" for="member_remember_me">
      <input type="checkbox" value="">
        <i class="input-helper"></i>
          Keep me signed in
    </label>
</div>

In my form, I have this:

<%= f.input :remember_me, class: 'checkbox inline', type: 'checkbox', as: :boolean if devise_mapping.rememberable? %>

And I cannot figure out how to get the image tag to show up inside the input field. What I get when the form is generated is this (missing the image tag):

<div class="checkbox">
  <input value="0" type="hidden" name="member[remember_me]">
    <label class="boolean optional" for="member_remember_me">
      <input class="boolean optional" type="checkbox" value="1" name="member[remember_me]" id="member_remember_me">Remember me
    </label>
</div>

I've tried this block that I thought should do it, but alas, no:

<%= f.input :remember_me, class: 'checkbox inline', type: 'checkbox', as: :boolean if devise_mapping.rememberable? do %>
  <i class="input-helper"></i>
<% end %>

Any suggestions? Do I need to write a custom wrapper to get the image tag to show?


回答1:


One option to put content inside any rails tag is to use

 "#{image_tag('filename.png')}".html_safe 

in place of the text, or using raw().



来源:https://stackoverflow.com/questions/34138715/add-image-tag-to-checkbox-input-field-with-rails-4-and-simple-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!