2016-09-18 6 views
2

私は基本的なTwilioアプリケーションを設定するためにthisチュートリアルに従ってみましたが、ルーティングに問題があるようです。Twilioリクエストルーティングの問題 - 経路が一致しない

私は、私はそれにメッセージを送信するときにこのエラーが返さ取得しています:ここで

ActionController::RoutingError (No route matches [POST] "/") 

は私のルートはここ

Rails.application.routes.draw do 
    resource :messages do 
    collection do 
     post 'reply' 
    end 
    end 
end 

ファイルでは、私のコントローラです:

class MessagesController < ApplicationController 
skip_before_filter :verify_authenticity_token 

    def reply 
    message_body = params["Body"] 
    from_number = params["From"] 
    boot_twilio 
    sms = @client.messages.create(
     from: Rails.application.secrets.twilio_number, 
     to: from_number, 
     body: "Hello there, thanks for texting me. Your number is #{from_number}." 
    ) 

    end 

    private 

    def boot_twilio 
    account_sid = Rails.application.secrets.twilio_sid 
    auth_token = Rails.application.secrets.twilio_token 
    @client = Twilio::REST::Client.new account_sid, auth_token 
    end 
end 

更新日18/09/16 19:12

私はおそらく私がここでやろうとしていることをより明確にすべきだったことを実感しました。アイデアは、twilio番号のテキストを書いて、そのリクエストをtwilio経由で元の送信者に返信するホストされたアプリに送信することです。

エラーログ

Started POST "/" for 54.161.31.172 at 2016-09-18 19:18:00 +0100 

ActionController::RoutingError (No route matches [POST] "/"): 
    actionpack (4.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' 
    web-console (2.3.0) lib/web_console/middleware.rb:20:in `block in call' 
    web-console (2.3.0) lib/web_console/middleware.rb:18:in `catch' 
    web-console (2.3.0) lib/web_console/middleware.rb:18:in `call' 
    actionpack (4.2.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' 
    railties (4.2.6) lib/rails/rack/logger.rb:38:in `call_app' 
    railties (4.2.6) lib/rails/rack/logger.rb:20:in `block in call' 
    activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `block in tagged' 
    activesupport (4.2.6) lib/active_support/tagged_logging.rb:26:in `tagged' 
    activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `tagged' 
    railties (4.2.6) lib/rails/rack/logger.rb:20:in `call' 

    actionpack (4.2.6) lib/action_dispatch/middleware/request_id.rb:21:in `call' 
    rack (1.6.4) lib/rack/methodoverride.rb:22:in `call' 
    rack (1.6.4) lib/rack/runtime.rb:18:in `call' 
    activesupport (4.2.6) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call' 
    rack (1.6.4) lib/rack/lock.rb:17:in `call' 
    actionpack (4.2.6) lib/action_dispatch/middleware/static.rb:120:in `call' 
    rack (1.6.4) lib/rack/sendfile.rb:113:in `call' 
    railties (4.2.6) lib/rails/engine.rb:518:in `call' 
    railties (4.2.6) lib/rails/application.rb:165:in `call' 
    rack (1.6.4) lib/rack/lock.rb:17:in `call' 
    rack (1.6.4) lib/rack/content_length.rb:15:in `call' 
    rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service' 
    /Users/tomgamon/.rbenv/versions/2.3.0/lib/ruby/2.3.0/webrick/httpserver.rb:140:in `service' 
    /Users/tomgamon/.rbenv/versions/2.3.0/lib/ruby/2.3.0/webrick/httpserver.rb:96:in `run' 
    /Users/tomgamon/.rbenv/versions/2.3.0/lib/ruby/2.3.0/webrick/server.rb:296:in `block in start_thread' 


    Rendered /Users/tomgamon/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates 
/rescues/_trace.html.erb (2.1ms) 
    Rendered /Users/tomgamon/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates 
/routes/_route.html.erb (1.9ms) 
    Rendered /Users/tomgamon/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates 
/routes/_table.html.erb (2.6ms) 
    Rendered /Users/tomgamon/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates 
/rescues/_request_and_response.html.erb (1.3ms) 
    Rendered /Users/tomgamon/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates 
/rescues/routing_error.html.erb within rescues/layout (124.1ms) 

レーキルート出力

Prefix Verb URI Pattern    Controller#Action 
      root GET /      messages#index 
reply_messages POST /messages/reply(.:format) messages#reply 
     messages POST /messages(.:format)  messages#create 
    new_messages GET /messages/new(.:format) messages#new 
edit_messages GET /messages/edit(.:format) messages#edit 
       GET /messages(.:format)  messages#show 
       PATCH /messages(.:format)  messages#update 
       PUT /messages(.:format)  messages#update 
       DELETE /messages(.:format)  messages#destroy 
+0

root 'messages#index'を交換し、あなたの完全なroutes.rbをファイルを表示するかということですか?こんにちは、@luissimo。 – luissimo

+0

非常に基本的な、目的のアプリなので、ルートファイル全体です。 – thrgamon

答えて

2

あなたはルートルート(ホーム・ページ)が設定されていません。

root 'controller#action' // root to the action of the controller you want to set as the index page a.k.a the homepage. 

をお使いの場合には、それは次のようになります:あなたは、あなたのroutes.rbをでこれを追加することによってそれを行うことができます

root 'messages#index' 

今、あなたのメッセージコントローラには、インデックスなどと呼ば空のメソッドを追加しますこの:

def index 
end 

は今すぐファイルを作成views/messages/index.html.erb

問題は今解決する必要があります。

EDIT

post '/' => "messages#index", as: "root

+0

ちょっと@luissimo - 残念ながら、私はまだエラーメッセージが表示されています! – thrgamon

+0

あなたの完全なエラーログを端末から表示することができます – luissimo

+0

元の質問 – thrgamon

関連する問題