Rails, a tag with nested HTML using FormBuilder and Devise with Bootstrap markup

I am working on the front end of a Rails 3.1 application. We use Twitter Bootstrap as the CSS Framework, we are developing as an authentication manager and I18n stone for localization.

This is the syntax for developing a flag with its label

<%= f.label :remember_me %> <%= f.check_box :remember_me %> 

And this, of course, generated HTML

 <label for="user_remember_me">Ricordati di me</label> <input name="user[remember_me]" type="hidden" value="0"> <input id="user_remember_me" name="user[remember_me]" type="checkbox" value="1"> 

Since Bootstrap adds this rule for display: block labels, the label and flag are not on the same line. To have the same line, I need HTML output like this

 <label for="user_remember_me"> Ricordati di me <input name="user[remember_me]" type="hidden" value="0"> <input id="user_remember_me" name="user[remember_me]" type="checkbox" value="1"> </label> 

As shown in the documentation markup form

You noticed that the label text is in Italian, the team member who provided the localization for Devised worked hard to find out how to do this, and I don’t want to get him to work on it again by introducing new localized strings.

I am well aware that the FormBuidler label method takes a block as an argument so that I can do

 <% f.label :remeber_me do %> <%= f.check_box :remember_me %> <% end %> 

But this leads to HTML whitout HTML! oo To be specific, this is what I get:

 <input name="user[remember_me]" type="hidden" value="0"> <input id="user_remember_me" name="user[remember_me]" type="checkbox" value="1"> 

I tried to look in the source code, the f.label method calls label , but I can only see that if there is a block, the text will not be printed and that the label and block will display label_tag template_object .

Before I dive into digging the source code and stay awake at night, I decided to wait a bit and ask the lifesafer community from StackOverflow about this.

Am I missing something? Am I f.label with the wrong block? Missing some parameter?

Thanks!!

+4
source share
2 answers

I don't know if you ever got this job ...

Running on Rails 3.2.6 is what I had to do:

 <%= f.label :remember_me do %> <%= f.check_box :remember_me %> Remember Me? <% end %> 

I hope this helps you since I came here to find the answer to the same problem and could not find it except through the trial version and error.

+5
source

If you need a label and a checkbox on the same line, you must include .form-inline in your

 <form class="form-inline"> <label for="user_remember_me">Ricordati di me</label> <input name="user[remember_me]" type="hidden" value="0"> <input id="user_remember_me" name="user[remember_me]" type="checkbox" value="1"> </form> 

http://jsfiddle.net/baptme/66TJY/

 <%= form_tag( :class => "form-inline") %> 
0
source

Source: https://habr.com/ru/post/1401069/


All Articles