Rails视图模板中的html.haml与haml

时间:2012-01-31 06:35:30

标签: html ruby-on-rails haml

在Rails中使用视图模板作为'.html.haml'和简单地'.haml'之间有什么区别? 例如,
show.html.haml
VS
show.haml

使用一个优于另一个有什么特别的优势吗?或者其中一个是标准做法?同样的问题也适用于其他类型的模板,例如'.erb'。

1 个答案:

答案 0 :(得分:5)

当您使用Rails的自动响应程序时,格式很重要。请参阅http://api.rubyonrails.org/classes/ActionController/MimeResponds.html#method-i-respond_with

例如,使用:

class CarsController < ActionController::Base
  respond_to :html, :js

  def index
    respond_with Car.all
  end
end

分别在查看app/views/cars/index.html.erbapp/views/index.js.erb时,应用会呈现http://localhost:3000/carshttp://localhost:3000/cars.js

此外,这是Rails-land中的既定惯例,所以即使你没有使用自动应答器,最好还是这样做。