This commit is contained in:
huang 2016-03-07 17:21:53 +08:00
parent ac8034ebc4
commit 6d68f96f39
9 changed files with 46 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,2 @@
module Api::V2::BaseHelper
end

View File

@ -0,0 +1,2 @@
module Api::V2::UsersHelper
end

View File

@ -0,0 +1,3 @@
json.user do
json.(@user, :id, :email, :name, :activated, :admin, :created_at, :updated_at)
end

View File

@ -29,7 +29,7 @@ RedmineApp::Application.routes.draw do
mount Mobile::API => '/api'
namespace :api do
namespace :v1 do
namespace :v2 do
resources :users, only: [:index, :create, :show, :update, :destroy]
# 原文有 microposts, 我们现在把它注释掉
# resources :microposts, only: [:index, :create, :show, :update, :destroy]

View File

@ -0,0 +1,4 @@
class AddAuthenticationTokenToUsers < ActiveRecord::Migration
def change
end
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe Api::V2::BaseController, :type => :controller do
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe Api::V2::UsersController, :type => :controller do
end