Generate custom attributes in check_box_tag

ruby-on-rails, ruby-on-rails-3, ruby-on-rails-3.1

Solution

You must give the custom attributes as fourth arguments, options. The first three arguments are name, value = "1", checked = false. See check_box_tag.

The code could be like this:

<%= check_box_tag :name, 1, false, data: { "toggle-completed" => "" } %>

Problem

I'd like to generate check box with custom html attributes (to use UJS later). Here is my view code ``` <%= check_box_tag "data-toggle-completed" => "" %> ``` it gives me ``` <input id="__data-toggle-completed______" name="{&quot;data-toggle-completed&quot;=&gt;&quot;&quot;}" type="checkbox" value="1"> ``` But I wanted ``` <input type="checkbox" data-toggle-completed=""> ``` How can I achieve this?

Original source