0
我可以通過API在我的網站上刪除和更新主題,但由於某種原因,我無法弄清楚爲什麼我無法創建主題。無法通過API創建主題
IM我的終端
curl -H "Content-type: application/json" -H "Authorization: Token jX4h98/B3Jx9R0JXYtqeRjzNBzLJs/AFbXckBnkcGKKcuSMUFJ5dqpPbDgFki4G0D5TVrbfvR685Jjo6CQ2qUg==" -X POST -d '{"topic": {"name":"Drastic Voyage: Part II", "description":"The team\'s mission inside Dr. Kovacs goes awry, and they are blacklisted by the CIA."}}' http://localhost:3000/api/v1/topics/
上運行,並且我得到的是我的終端上>
。
這裏是我的創建方法在我的API主題控制器:
def create
topic = Topic.new(topic_params)
if topic.valid?
topic.save!
render json: topic.to_json, status: 201
else
render json: {error: "Topic is invalid", status: 400}, status: 400
end
end
我的路線:
namespace :api do
namespace :v1 do
resources :users, only: [:index, :show, :create, :update]
resources :topics, except: [:edit, :new]
end
end
任何想法可能我是做錯了什麼?
謝謝你工作:) –