Vig*_*esh 7 html haml ruby-on-rails
在Rails中使用视图模板作为'.html.haml'和简单地'.haml'之间有什么区别?例如,
show.html.haml
vs
show.haml
使用一个优于另一个有什么特别的优势吗?或者其中一个是标准做法?同样的问题也适用于其他类型的模板,例如'.erb'.
当您使用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
Run Code Online (Sandbox Code Playgroud)
该应用程序将呈现app/views/cars/index.html.erb和app/views/index.js.erb观看时http://localhost:3000/cars和http://localhost:3000/cars.js分别.
另外,这是Rails-land中的既定惯例,所以即使您没有使用自动响应器,最好还是这样做.