簡體   English   中英

simple_form添加沒有值的屬性

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM