ruby-on-rails – 不赞成在模板名称中传递模板处理程序.意思?

我一直在试图弄清楚这个错误信息是什么意思,但是不能弄清楚.

这是完整的信息

DEPRECATION WARNING: Passing a template handler in the template name
is deprecated. You can simply remove the handler name or pass render
:handlers => [:jbuilder] instead. (called from realtime at
/Users/Arel/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/benchmark.rb:295)

这里是代码

it "is logged in" do
    post "/api/v1/login",user_login: {email: 'test@test.com',password: '12345678' }
    response.status.should be(201)
  end

什么是模板处理程序,为什么它认为我在模板名称中传递它?什么模板?

编辑:

Sessions_controller.控制器被登录路径调用.

class Api::V1::SessionsController < Devise::SessionsController
    before_filter :authenticate_user!,except: [:create,:destroy]
    before_filter :ensure_params_exist
    skip_before_filter :verify_authenticity_token

  def create
    resource = User.find_for_database_authentication(email: params[:user_login][:email])
    return invalid_login_attempt unless resource

    if resource.valid_password?(params[:user_login][:password])
        sign_in("user",resource)
        resource.ensure_authentication_token!
        render 'api/v1/sessions/new.json.jbuilder',status: 201
        return
    end
    invalid_login_attempt
  end

  def destroy
        current_user.reset_authentication_token
        render json: {success: true}
  end

  protected

  def ensure_params_exist
    return unless params[:user_login].blank?
    render json: {success: false,message: "missing user_login parameter"},status: 422
  end

  def invalid_login_attempt
    render 'api/v1/sessions/invalid.json.jbuilder',status: 401
  end
end

解决方法

当您从控制器执行渲染时,您不再需要将文件格式或处理程序作为文件名的一部分传递.相反,你会这样做:
render 'api/v1/sessions/new',:formats => [:json],:handlers => [:jbuilder],status: 201

这提供了以多种格式呈现的动作的便利.例如,您可以简单地传递一系列接受的格式,而不是为每种格式呈现单独的模板:

render 'api/v1/sessions/foo',:formats => [:html,:js,:xml]
#=> handles html,js,and xml requests
#=> renders to foo.html,foo.js,and foo.xml,respectively

将数组传递给:构建器允许您指定在呈现时使用的模板构建器:

render 'api/v1/sessions/foo',:handlers => [:jbuilder]
#=> renders to foo.json.jbuilder

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...