Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using simple_form to set data-content

I'm using Simple_form with Rails 3.2.1

All fine, except that I need to set the 'data-content' attribute for the input_html for bootstrap popover

However, when I use the following Rails/Ruby doesn't like the code as there is a dash in the 'data-content' method:

<%= f.input :first_name, :required => true, :label => "First Name", :autofocus => true, :input_html => {:rel => "tooltip", :title => "Testing!", :data-content => "Popover content"} 

and i get an error:

 undefined local variable or method `content'

Does anyone know how you can set data-content for input elements using simple_form???

thanks

like image 223
bobomoreno Avatar asked Aug 03 '26 06:08

bobomoreno


2 Answers

You can't use - in ruby symbols but you can use a string like "data-content". So, this will probably work:

<%= f.input :first_name, :required => true, :label => "First Name", :autofocus => true, :input_html => {:rel => "tooltip", :title => "Testing!", 'data-content'=> "Popover content"} 
like image 55
TimPetricola Avatar answered Aug 05 '26 18:08

TimPetricola


I think you can use the data setting as follows:

<%= f.input blar..., :input_html => { :data => { content: => "Popover content"}}

this should give you an attribute data-content="Popover content"

like image 31
nodrog Avatar answered Aug 05 '26 19:08

nodrog



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!