我有以下代码段
def range
respond_to do |format|
if params[:start] && params[:end]
begin
dstart = Time.parse(params[:start])
dend = Time.parse(params[:end])
rescue => e
format.json { render :json => { :status => :unprocessable_entity, :error => e.message }} and return
end
...
它工作得很好,并使它成为底部的东西......
...
format.json { render :json => { :status => :ok, :posts => @res.to_json(:only => [:date, :content, :user_id]) } }
else
format.json { render :json => { :status => :unprocessable_entity, :error => "must have a _start_ and _end_ date" } }
...
问题是当发生异常并rescue
调用该部分时,Rails 不会以 json 响应,而是告诉我“模板缺失”。我的语法有问题吗?