为什么带有额外参数的button_tag会出错?

时间:2013-10-15 14:38:41

标签: ruby-on-rails html5 syntax-error form-helpers

我有一个表格和一个按钮:

= button_tag( "×" , type: "button", html: {class: "close", aria-hidden: "true"},  data: {dismiss: "alert"} )

它从twitter bootstrap [http://getbootstrap.com/components/#alerts]转换为rails:

<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>

但是rails变种出错:

SyntaxError in Search#get_search
Showing /.../app/views/search/new.html.slim where line #58 raised:

/.../app/views/search/new.html.slim:58: syntax error, unexpected tLABEL
...: {class: "close", aria-hidden: true},  data: {dismiss: "ale...
...                               ^
/.../app/views/search/new.html.slim:58: syntax error, unexpected ')', expecting keyword_end
... {dismiss: "alert"} )))).to_s)); 
...                               ^

aria-hidden: "true"dismiss: "alert"的内容错误

为什么会这样?我使用了不同的变体,抱怨[http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-button_tag]:

button_tag(content_or_options = nil, options = nil, &block)

1 个答案:

答案 0 :(得分:1)

不允许使用此语法:

aria-hidden: "true"

将其替换为:

:"aria-hidden" => "true"

"aria-hidden" => "true"

aria: { hidden: true }