我想对POST request
本地开发人员进行这样的操作:
HTTParty.post('http://localhost:3000/fetch_heroku',
:body => {:type => 'product'},)
但是,它会从服务器控制台报告
Started POST "/fetch_heroku" for 127.0.0.1 at 2016-02-03 23:33:39 +0800
ActiveRecord::SchemaMigration Load (0.0ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by AdminController#fetch_heroku as */*
Parameters: {"type"=>"product"}
Can't verify CSRF token authenticity
Completed 422 Unprocessable Entity in 1ms
这是我的控制器和路由设置,非常简单。
def fetch_heroku
if params[:type] == 'product'
flash[:alert] = 'Fetch Product From Heroku'
Heroku.get_product
end
end
post 'fetch_heroku' => 'admin#fetch_heroku'
我不确定该怎么做?关闭CSRF当然可以,但是我认为在创建这样的API时应该是我的错误。
我还有其他需要设置的设置吗?
protect_from_forgery with: :null_session
。