javascript - 使用 simple_form 设置数据内容

标签 javascript ruby-on-rails twitter-bootstrap simple-form

我在 Rails 3.2.1 中使用 Simple_form

一切正常,除了我需要为 Bootstrap 弹出窗口的 input_html 设置“data-content”属性

但是,当我使用以下 Rails/Ruby 时,我不喜欢这些代码,因为“data-content”方法中有一个破折号:

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

我得到一个错误:

 undefined local variable or method `content'

有谁知道如何使用 simple_form 为输入元素设置数据内容???

谢谢

最佳答案

你不能在 ruby​​ 符号中使用 - 但你可以使用像 "data-content" 这样的字符串。所以,这可能会起作用:

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

关于javascript - 使用 simple_form 设置数据内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10063137/

相关文章:

javascript - 如何在要加载到浏览器中的模块中导入类型信息

javascript - 如何从 Javascript 生成 Vue 组件

ruby-on-rails - Rails Carmen 从代码中获取国家名称和州名称

css - Twitter Bootstrap - 创建预览

html - 根据按钮行宽调整div宽度

javascript - JS - 解析\n 和其他对象到相关 HTML

javascript - 在通过电子邮件发送 Blade 模板之前包含/执行 JS

ruby-on-rails - idn-ruby 捆绑安装时出错

javascript - 无法访问 Javascript 标记内的 Rails 变量

css - Bootstrap - 我们必须使用行和列吗?