简体   繁体   English

使用 simple_form 设置数据内容

[英]Using simple_form to set data-content

I'm using Simple_form with Rails 3.2.1我在 Rails 3.2.1 中使用 Simple_form

All fine, except that I need to set the 'data-content' attribute for the input_html for bootstrap popover一切都很好,除了我需要为引导弹出窗口的 input_html 设置“数据内容”属性

However, when I use the following Rails/Ruby doesn't like the code as there is a dash in the 'data-content' method:但是,当我使用以下 Rails/Ruby 时,我不喜欢这些代码,因为“数据内容”方法中有一个破折号:

<%= 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???有谁知道如何使用 simple_form 为输入元素设置数据内容???

thanks谢谢

You can't use - in ruby symbols but you can use a string like "data-content" .你不能在 ruby 符号中使用-但你可以使用像"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"} 

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"这应该给你一个属性data-content="Popover content"

You can't use hyphens in your symbol names.您不能在符号名称中使用连字符。 :data-content is interpreted as :data - content => the symbol :data minus `content. :data-content被解释为:data - content => 符号:data减去 `content。

Instead, wrap it in quotes ... "data-content" => "Popover content"...相反,将其用引号引起来... "data-content" => "Popover content"...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM