我不太确定为什么会收到此错误:
Routing Error
No route matches [POST] "/transactions/new"
这是我的配置文件:
TwerkApp::Application.routes.draw do
get "transactions/new"
resources :transactions
这是我的控制器:
class TransactionsController < ApplicationController
def new
@transaction = Transaction.new(current_user.email, 100.0, params[:transaction])
end
def create
@transaction = Transaction.new(current_user.email, 100.0, params[:transaction])
if @transaction.charge
flash[:success] = 'Thanks for the moolah!'
redirect_to root_path
else
flash[:error] = @transaction.errors.first
render :new
end
end
end
这是新的交易表格:
= form_for :transaction do |f|
= label_tag :card_number, "Credit Card Number"
= text_field_tag :card_number, nil, name: nil, :value => "4111111111111111", class: "cc-number"
%p
= label_tag :card_code, "Security Code on Card (CVV)"
= text_field_tag :card_code, nil, name: nil, :value => "123", class: "cc-csc"
%p
= label_tag :card_month, "Card Expiration"
= select_month nil, {add_month_numbers: true}, {name: nil, class: "cc-em"}
= select_year Date.new(2020), {start_year: Date.today.year, end_year: Date.today.year+15}, {name: nil, class: "cc-ey"}
%br
= f.submit
和耙路线:
transactions GET /transactions(.:format) transactions#index
POST /transactions(.:format) transactions#create
new_transaction GET /transactions/new(.:format) transactions#new
edit_transaction GET /transactions/:id/edit(.:format) transactions#edit
transaction GET /transactions/:id(.:format) transactions#show
PUT /transactions/:id(.:format) transactions#update
DELETE /transactions/:id(.:format) transactions#destroy
有没有人有任何想法?