我試過以下this教程來設置一個基本的Twilio應用程序,但我似乎有路由問題。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
顯示您完整的routes.rb文件或者是它? – luissimo
嘿,@luissimo。這是一個非常基本的,一個目的應用程序,所以這是整個路線文件。 – thrgamon