Search code examples
ruby-on-railsruby-on-rails-3zeroclipboard

Change button to Image in Copy to Clipboard - zeroclipboard-rails


I Added Copy to Clipboard Functionality that working perfect but now I want to change button to Image. How can I change that?. I added simply image_tag but image comes on button tag.

Anybody have an idea How can I do this?

My script like

    <button class='my_clip_button' data-clipboard-target='fe_text' data-clipboard-text='Default clipboard text from attribute' id='d_clip_button' title='Click me to copy to clipboard.'>
      <b><%= image_tag("/assets/copy2.png") %></b>
    </button>

Solution

  • Looking into rails view helpers gives The button tag allows richer labels such as images and emphasis, so this helper will also accept a block.

    Why don't you simply give the image_tag inside a block like:

    <%= button_tag( :class => "button_green") do %>
      <%= image_tag("copy2.png") %>
    <% end %> 
    

    OR

    If it's a form then you can try image_tag_submit

    <%= image_submit_tag("copy2.png") %>
    # => <input alt="Login" src="/assets/images/copy2.png" type="image" />
    

    OR

    As mentioned in comment you can simply give background-image to your button and then adjust the image using background-position property

    button {
      background-image:url("copy2.png");
    }