2015-07-12 96 views
1

我很新的RoR,我正在學習飛行。這就是說,我試圖解析從Formstack發送到我的腳本的POST請求。我可以通過訪問它的URL來查看和運行腳本,並且它運行得很好,當我將Webhook指向Formstack中的URL時,沒有任何反應。我從命令行運行了下面的curl請求,並且返回了404錯誤。404當發送JSON到RoR與捲曲

curl -H "Content-Type: application/json" -d '{"FormID":"1234","UniqueID":"1234","Name":{"first":"John","last":"Smith"},"Email":"[email protected]","Phone":"(555) 555-555","Company":"Test Company"}' -X POST "http://scripturl.com" 

我檢查了與requestb.in一起發送的數據,並且一切正常發送。那麼爲什麼當JSON數據被髮送時它會返回一個404錯誤,但是當我在瀏覽器中查看它時運行得很好?我的示例代碼如下。

firstName = params[:Name]["first"] 
lastName = params[:Name]["last"] 
email = params["Email"] 
company = params["Company"] 
phone = params["Phone"] 
client.create('contact', firstname: firstName, lastname: lastName, emailaddress1: email, subject: "Test", companyname: company, mobilephone: phone) 

這裏是日誌/ production.log的內容:

rack (1.6.4) lib/rack/sendfile.rb:113:in `call' 
    railties (4.2.3) lib/rails/engine.rb:518:in `call' 
    railties (4.2.3) lib/rails/application.rb:165:in `call' 
    passenger (5.0.13) lib/phusion_passenger/rack/thread_handler_extension.rb:94:in `process_request' 
    passenger (5.0.13) lib/phusion_passenger/request_handler/thread_handler.rb:157:in `accept_and_process_next_request' 
    passenger (5.0.13) lib/phusion_passenger/request_handler/thread_handler.rb:110:in `main_loop' 
    passenger (5.0.13) lib/phusion_passenger/request_handler.rb:415:in `block (3 levels) in start_threads' 
    passenger (5.0.13) lib/phusion_passenger/utils.rb:111:in `block in create_thread_and_abort_on_exception' 
+0

你在軌道日誌中遇到什麼錯誤? –

+0

用輸出編輯原始文章 – Kyle

回答

1

我發現這個問題。我不得不添加以下內容的config/routes.rb文件:

post '/add' => 'contacts#add' 

然後在控制器/ application_controller.rb,則需要更換此:

protect_from_forgery with: :exception 

有了這個:

protect_from_forgery with: :null_session