This commit is contained in:
parent
ac8034ebc4
commit
6d68f96f39
|
@ -0,0 +1,15 @@
|
||||||
|
class Api::V2::BaseController < ApplicationController
|
||||||
|
# disable the CSRF token
|
||||||
|
protect_from_forgery with: :null_session
|
||||||
|
|
||||||
|
# disable cookies (no set-cookies header in response)
|
||||||
|
before_action :destroy_session
|
||||||
|
|
||||||
|
# disable the CSRF token
|
||||||
|
skip_before_action :verify_authenticity_token
|
||||||
|
|
||||||
|
def destroy_session
|
||||||
|
request.session_options[:skip] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,9 @@
|
||||||
|
class Api::V2::UsersController < ApplicationController
|
||||||
|
def show
|
||||||
|
@user = User.find(params[:id])
|
||||||
|
|
||||||
|
# 原文使用 Api::V1::UserSerializer
|
||||||
|
# 我们现在使用 app/views/api/v1/users/show.json.jbuilder
|
||||||
|
# render(json: Api::V1::UserSerializer.new(user).to_json)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,2 @@
|
||||||
|
module Api::V2::BaseHelper
|
||||||
|
end
|
|
@ -0,0 +1,2 @@
|
||||||
|
module Api::V2::UsersHelper
|
||||||
|
end
|
|
@ -0,0 +1,3 @@
|
||||||
|
json.user do
|
||||||
|
json.(@user, :id, :email, :name, :activated, :admin, :created_at, :updated_at)
|
||||||
|
end
|
|
@ -29,7 +29,7 @@ RedmineApp::Application.routes.draw do
|
||||||
mount Mobile::API => '/api'
|
mount Mobile::API => '/api'
|
||||||
|
|
||||||
namespace :api do
|
namespace :api do
|
||||||
namespace :v1 do
|
namespace :v2 do
|
||||||
resources :users, only: [:index, :create, :show, :update, :destroy]
|
resources :users, only: [:index, :create, :show, :update, :destroy]
|
||||||
# 原文有 microposts, 我们现在把它注释掉
|
# 原文有 microposts, 我们现在把它注释掉
|
||||||
# resources :microposts, only: [:index, :create, :show, :update, :destroy]
|
# resources :microposts, only: [:index, :create, :show, :update, :destroy]
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
class AddAuthenticationTokenToUsers < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Api::V2::BaseController, :type => :controller do
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Api::V2::UsersController, :type => :controller do
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in New Issue