在rake路由过程中,url路径后面附加的(.:format)是什么?



当我运行rake routes时,我得到这样的东西:

signin        /signin(.:format)                            application#signin

中间的(.:format)是什么?

可选格式。它匹配如下url:

/signin
/signin.html
/signin.json

这种格式可以在控制器中使用。例如:

class UsersController < ApplicationController
  def index
    @users = User.all
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render xml: @users}
      format.json { render json: @users}
    end
  end
end

这个代码片段来自Action Controller Overview。详情请参见路由指南

最新更新