2012-08-09 46 views
2

似乎无法找到这个问题的答案 - 什么是haml语法添加样式或类样式的元素内的轨道form_for?哈姆添加样式来形成元素

我处理的代码是

.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

text_area是需要(对象,方法,和可选项)的方法(http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-text_area)

当你有它附加到表单对象,就扣住对象,因此它变得text_area(方法,选项= {})

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

= a.text_area :description, class: "description", style: "font-size: 45" 
+0

大 - 感谢。逐渐认识语法。 – jmc 2012-08-09 04:02:12

+0

似乎对我来说,添加需要格式化为轨道散列?可能有助于纠正任何读这种语法混淆的人。 – jmc 2012-08-09 04:05:08