1

私の質問は、名前付きルートを使用したコントローラー/アクションへのマッピングに関係しています。'/profile'を'customers#show'にマップしようとしています。私のルートファイルは次のようになります。

    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"}

私が顧客をリソースとして宣言しているため、実際に「customers#edit」へのルートがあるため、これは奇妙に思えます。

ただし、「localhost:3000 / signin」に移動すると、「/ profile」のルーティング先である「customers#show」にルーティングされます。

ルートファイルでルートが「1回限り」のようですが、理由がわかりません。どんな助けでも大歓迎です。

ありがとう

更新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
4

1 に答える 1

0

あなたの意見を確認してください。

ユーザープロファイルを編集するためのリンクはありますか?

実際には正しいコントローラーとアクションにルーティングしているように見えますが、たとえば、edit_customer_pathリンクにIDを渡さないなど、rakeがルーティングできないリンクがいくつかあります。

于 2013-02-22T00:53:56.690 に答える