Rails 4没有路由匹配[POST]“/ transactions / new”

时间:2015-12-04 04:47:02

标签: ruby-on-rails-4

我正在尝试关注此tutorial,但我在表单提交时收到此错误消息:

No route matches [POST] "/transactions/new"

的routes.rb

resources :transactions, only: [:new, :create]

交易#new view

<%= form_tag transactions_path do%>
   <%= fields....%>  
<%=submit_tag "Pay #{@course.price}$", :class=>"btn" %>

当我耙路线时

transactions_path   POST    /transactions(.:format) transactions#create
new_transaction_path    GET /transactions/new(.:format) transactions#new
create_transaction_path POST    /transactions(.:format) transactions#new

控制器

def new
  @client_token = generate_client_token
  @course = Course.find(params[:course_id])      
end

以下是完整的跟踪:

Routing Error
No route matches [POST] "/transactions/new"

Rails.root: C:/Sites/christian

Application Trace | Framework Trace | Full Trace
actionpack (4.2.5) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.5) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.5) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.5) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.5) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.5) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.5) lib/rails/rack/logger.rb:20:in `call'
quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
actionpack (4.2.5) 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.5) 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.5) lib/action_dispatch/middleware/static.rb:116:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.5) lib/rails/engine.rb:518:in `call'
railties (4.2.5) 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'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'

1 个答案:

答案 0 :(得分:1)

错误有意义。删除create_transaction_path路由,即它只应显示

transactions_path   POST    /transactions(.:format) transactions#create
new_transaction_path    GET /transactions/new(.:format) transactions#new

再试一次