2

似乎无法找到这个问题的答案 - 向 rails form_for 中的元素添加样式或类样式的 haml 语法是什么?

我正在处理的代码是

.row.form
.threecol
.sevencol
    = form_for @article do |a|
      %h3= a.label "title"
      =    a.text_field :title 
      %h3= a.label "description"
      =    a.text_area :description
      %h3= a.label "body"
      =    a.text_area :body
      %br/
      =  a.submit "Post Article"
 .twocol.last

我想为文本区域描述元素添加样式。我已经尝试过(其中 new_desc 是类样式)

= a.text_area.new_desc :description

= a.text_area { :style ... } :description

但两者都未能编译。任何人都可以帮助解决这个(希望是微不足道的)问题吗?

4

1 回答 1

5

text_area 是一种采用(对象、方法和选项)的方法 (http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-text_area)

当您将其附加到表单对象时,您会保留该对象,因此它变为 text_area(method, options={})

= a.text_area :description, class: "description"

或者

= a.text_area :description, class: "description", style: "font-size: 45"
于 2012-08-09T03:07:24.750 回答