[英]simple_form adding attributes with no value
我在带有AngularJS和haml的Rails 3.2应用程序下使用simple_form。
我已经在此输入字段中存储了成本,我想使用angularjs指令“ form-cents-to-dollars”,但simple_form input_html选项需要一个带有值的键,这只是键或属性就像AngularJS所说的那样。
= f.input :cost_per_unit_cents,
input_html: {class: 'money',
"ng-model" => "timesheet.cost_per_unit_cents",
"ng-init" => "timesheet.cost_per_unit_cents=#{@timesheet.cost_per_unit_cents}",
"ng-change" => "line_item_service.calc_total()",
"form-cents-to-dollars" }
运行此代码时出现的错误是“语法错误,意外的},期望=>。
是否可以使用简单的形式仅设置“键”? 还是有一种方法可以将它作为可以与attribute指令一起使用的键/值对发送给AngularJS?
有点骇人听闻,但您始终可以使用空字符串作为值。
= f.input :cost_per_unit_cents,
input_html: {class: 'money',
"ng-model" => "timesheet.cost_per_unit_cents",
"ng-init" => "timesheet.cost_per_unit_cents=#{@timesheet.cost_per_unit_cents}",
"ng-change" => "line_item_service.calc_total()",
"form-cents-to-dollars" => "" }
Rails将丢弃空字符串,并在输入元素上添加form-cents-to-dollars作为属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.