我遇到了一个小问题,这是我创建的新地方没有经过的。
这是我的curl命令:
curl -H 'Content-Type: application/json' -X POST -d '{"place": {"name": "the stroke", "address": "the stroke YOLO", "description":"YOLOOOOO", "phone":"9128911", "website":"www.thestrokes.com"}}' http://localhost:3000/api/v1/places
-i -H 'Authorization: Token token="8f8315d4892044479450ef3403c0af95"'
这是我的地方控制器要点:
module Api
module V1
class PlacesController < Api::ApiController # Api::BaseController
respond_to :json
before_action :authenticate #This authenticate method inherit from Api Controller
skip_before_action :verify_authenticity_token
def index
respond_with @user.places
end
def show
respond_with Place.find(params[:id])
end
def create
respond_with Place.create(params[:product])
end
def update
respond_with Place.update(params[:id], params[:products])
end
def destroy
respond_with Place.destroy(params[:id])
end
# private
# def authenticate
# authenticate_or_request_with_http_token do |token, options|
# current_user.find_by(access_token: token)
# end
# end
end
end
end
这是我的日志:
Started POST "/api/v1/places" for ::1 at 2015-07-31 17:07:10 +0800
Processing by Api::V1::PlacesController#create as JSON
Parameters: {"place"=>{"name"=>"the stroke", "address"=>"the stroke YOLO", "description"=>"YOLOOOOO", "phone"=>"9128911", "website"=>"www.thestrokes.com"}}
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."access_token" = ? LIMIT 1 [["access_token", "8f8315d4892044479450ef3403c0af95"]]
(0.1ms) begin transaction
(0.1ms) rollback transaction
Completed 422 Unprocessable Entity in 6ms (Views: 0.2ms | ActiveRecord: 0.3ms)
希望有人可以帮我解决这个问题。