2013-02-21 59 views
1

我的問題與映射到使用命名路由的控制器/操作有關。我試圖將'/ profile'映射到'customers#show'。我的路線文件看起來像這樣:Rake routes'match'mapping to the wrong action

root :to => 'pages#home' 

    ## named routes 
    match "profile" => "customers#show", :as => 'profile' 
    match 'signin' => 'sessions#new', :as => 'signin' 
    match 'signout' => 'sessions#destroy', :as => 'signout' 

    resources :customers do 
    member do 
     get 'add_card' 
     post 'submit_card' 
    end 
    end 


    resources :payments, :only => [:show, :new] 
    delete 'payments/delete_recurring_payment' 
    post 'payments/submit_non_recurring' 
    post 'payments/submit_recurring' 

    resources :sessions, :only => [:create, :destroy, :new] 

運行「耙路線」給了我這樣的:

      root  /           pages#home 
         profile  /profile(.:format)       customers#show 
         signin  /signin(.:format)       sessions#new 
         signout  /signout(.:format)       sessions#destroy 
      add_card_customer GET /customers/:id/add_card(.:format)   customers#add_card 
     submit_card_customer POST /customers/:id/submit_card(.:format)   customers#submit_card 
        customers GET /customers(.:format)       customers#index 
           POST /customers(.:format)       customers#create 
       new_customer GET /customers/new(.:format)      customers#new 
       edit_customer GET /customers/:id/edit(.:format)    customers#edit 
        customer GET /customers/:id(.:format)      customers#show 
           PUT /customers/:id(.:format)      customers#update 
           DELETE /customers/:id(.:format)      customers#destroy 
        new_payment GET /payments/new(.:format)      payments#new 
         payment GET /payments/:id(.:format)      payments#show 

這裏就是我難倒。當我去爲localhost:3000/profile文件,我得到一個錯誤的路由這樣說:

No route matches {:action=>"edit", :controller=>"customers"} 

這似乎很奇怪,因爲確實是「客戶#編輯」的路線,由於我的客戶聲明作爲一種資源。

然而,當我去的「localhost:3000 /登入」我被路由到「客戶#秀」這是我想「/資料」來的路線。

好像我是航線「一次性」在我的路線文件,但我不知道爲什麼。任何幫助將非常感激。

感謝

更新1:添加我的客戶控制器

class CustomersController < ApplicationController 
    layout "payments_layout" 

    def show 
    @customer = current_user 
    get_account_info(@customer) 
    get_payment_history(@customer, 10) 
    end 

    def new 
    @title = 'Create an account' 
    @customer = Customer.new 
    end 

    def edit 
    @customer = current_user 
    get_account_info(@customer) 
    end 

    def update 
    @customer = current_user 
    if @customer.update(params[:customer]) 
     redirect_to @customer 
    else 
     @card_message = "Use this form to add a credit card to your account. You must have a credit card associated with your account in 
         in order to make payments on our system." 
     get_account_info(@customer) 
     render 'edit' 
    end 
    end 

    def create 
    @customer = Customer.new(params[:customer]) 
    if @customer.save_and_get_stripe_id 
    sign_in(@customer) 
    redirect_to @customer 
    else 
    @title = 'Create an account' 
    render 'new' 
    end 
    end 

    def add_card 
    @customer = current_user 
    get_account_info(@customer) 
    @card_message = "Use this form to add a credit card to your account. You must have a credit card associated with your account in 
        in order to make payments on our system." 
    end 

    def submit_card 
    @customer = current_user 
    res = @customer.add_or_update_card(params) 
    if res 
     redirect_to @customer 
    else 
     @error = res 
     customer.get_account_info(@customer) 
     render 'add_card' 
    end 
    end 

end 
+0

你可以幫助你的客戶控制器嗎? – damienbrz 2013-02-21 23:44:59

回答

0

檢查你的意見。

你有一個鏈接編輯您的用戶資料?

好像你到正確的控制器和實際行動路線,但有一些鏈接,耙不能路由,例如你不會將ID傳遞給你的edit_customer_path鏈接。

相關問題