Quantcast
Channel: Ruby – My Programming Blog
Viewing all articles
Browse latest Browse all 12

RAILS, HAML : How to put Checkbox and label on the same line, with translations

$
0
0

Hey guys!

Today I have decided to share with you little secret, that can save you quite some time, while writing templates with HAML.

While creating a form for one of the projects, I needed to put a checkbox within the same line as label and also I had to make my label a “translation”.

I googled and the closest which I was able to find was:

http://stackoverflow.com/questions/9774555/nesting-ruby-on-rails-haml-checkbox-in-label-tag

However, It didn’t really solve my “translation” problem.

Initially my code looked like this:

= simple_form_line do
  = f.label t('.send_email')
  = f.check_box :send_email, class: "checkbox"

.send_email in this case is a translation from my eng.yml file which equals to “Send credentials to user by email”.

The code produced this output:

Image

However, what I needed my checkbox and message to be on the same line. This is how I was able to solve it:

= simple_form_line do
  = f.label t('.send_email')
  = f.check_box :send_email, class: "checkbox"

)

(Sorry if wordpress screwed indentation!!!)

And here is how output looks like:

Image

That’s it for today!

Have a wonderful day!

Regards,

Anatoly

The post RAILS, HAML : How to put Checkbox and label on the same line, with translations appeared first on My Programming Blog.


Viewing all articles
Browse latest Browse all 12

Trending Articles