在Rails中使用视图模板作为'.html.haml'和简单地使用'.haml'有什么区别?例如,show.html.haml
与show.haml
使用一个比另一个有什么特别的优点吗?或者其中一个是标准做法?同样的问题也适用于其他类型的模板,如'.erb'.
使用Rails的自动响应程序时,格式很重要。看见http://api.rubyonrails.org/classes/ActionController/MimeResponds.html#method-我回应了。
例如:
class CarsController < ActionController::Base
respond_to :html, :js
def index
respond_with Car.all
end
end
应用程序将在查看http://localhost:3000/cars
和http://localhost:3000/cars.js
时分别渲染app/views/cars/index.html.erb
和app/views/index.js.erb
。
此外,这是Rails领域的一个既定惯例,所以无论如何都这样做是个好主意,即使你没有使用自动响应程序。