简体   繁体   中英

What does Passing a template handler in the template name is deprecated. mean?

I've been trying to figure out what this error message means, but can't figure it out.

Here is the full message

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)

and here is the code:

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

What is a template handler , and why does it think I'm passing it in the template name ? What template?

EDIT:

Sessions_controller . The controller being called by the login path.

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

When rendering from your controller action, you no longer need to pass the file format or handler as part of the file name. Instead, you'd do this:

render 'api/v1/sessions/new', :formats => [:json], :handlers => [:jbuilder], status: 201

This provides convenience for actions that render out in multiple formats. For instance, rather than rendering a separate template for each of the formats, you can simply pass an array of accepted formats to render :

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

Passing an array to :builders allows you to specify the template builder(s) to use when rendering:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM