मैं 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 को बंद करने के लिए निश्चित रूप से काम करेगा, लेकिन मुझे लगता है कि इस तरह की एपीआई बनाते समय मेरी गलती होनी चाहिए।
क्या कोई अन्य सेटअप है जो मुझे करने की आवश्यकता है?
protect_from_forgery with: :null_session।