Note that there are some explanatory texts on larger screens.

plurals
  1. PORails, label with nested HTML using FormBuilder and Devise, with Bootstrap markup
    primarykey
    data
    text
    <p>I am working on the front-end part of a Rails 3.1 application. We are using a Twitter Bootstrap as CSS Framework, Devise as the authentication manager and the I18n gem for localization.</p> <p>This is the devise syntax for a checkbox with its label</p> <pre><code>&lt;%= f.label :remember_me %&gt; &lt;%= f.check_box :remember_me %&gt; </code></pre> <p>And this of course is the generated HTML</p> <pre><code>&lt;label for="user_remember_me"&gt;Ricordati di me&lt;/label&gt; &lt;input name="user[remember_me]" type="hidden" value="0"&gt; &lt;input id="user_remember_me" name="user[remember_me]" type="checkbox" value="1"&gt; </code></pre> <p>Since Bootstrap adds this rule for the labels <code>display: block</code>, the label and the checkbox are not in the same line. To have the on the same line I need an HTML output like this</p> <pre><code>&lt;label for="user_remember_me"&gt; Ricordati di me &lt;input name="user[remember_me]" type="hidden" value="0"&gt; &lt;input id="user_remember_me" name="user[remember_me]" type="checkbox" value="1"&gt; &lt;/label&gt; </code></pre> <p>As shown in the <a href="http://twitter.github.com/bootstrap/base-css.html#forms" rel="nofollow">forms markup documentation</a></p> <p>You will have noticed that the label text is in Italian, the team member who provided localization for Devised worked hard to find out how to do so, and I do not want to force he to work on it again introducing new localized strings.</p> <p>I am aware of the nice fact that the <code>FormBuidler</code> <code>label</code> method accepts a block as an argument so I could do</p> <pre><code>&lt;% f.label :remeber_me do %&gt; &lt;%= f.check_box :remember_me %&gt; &lt;% end %&gt; </code></pre> <p>But this produce an HTML output <b>whitout</b> the label! o.O To be specific this is what I get:</p> <pre><code>&lt;input name="user[remember_me]" type="hidden" value="0"&gt; &lt;input id="user_remember_me" name="user[remember_me]" type="checkbox" value="1"&gt; </code></pre> <p>I tried to look in the source code, the <a href="https://github.com/rails/rails/blob/defb751681640e11f2187439acdaaa12ca9b805f/actionpack/lib/action_view/helpers/form_helper.rb#L1313" rel="nofollow"><code>f.label</code> method</a> calls the <a href="https://github.com/rails/rails/blob/defb751681640e11f2187439acdaaa12ca9b805f/actionpack/lib/action_view/helpers/form_helper.rb#L658" rel="nofollow"><code>label</code> method</a>, but I can only see that if there is a block no text will be printed and that the label and block will be rendered by the <code>label_tag</code> of the <code>template_object</code>.</p> <p>Before diving into a source code digging, and a no sleep night, I decided to wait a moment and ask the lifesafer community of StackOverflow for help.</p> <p>Am I missing something? I am calling <code>f.label</code> with block in the wrong way? Is some parameter missing?</p> <p>Thanks!!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload