Note that there are some explanatory texts on larger screens.

plurals
  1. PORake routes 'match' mapping to the wrong action
    primarykey
    data
    text
    <p>My question has to do with mapping to controllers/actions using named routes. I am trying to map '/profile' to 'customers#show'. My routes file looks like this:</p> <pre><code> root :to =&gt; 'pages#home' ## named routes match "profile" =&gt; "customers#show", :as =&gt; 'profile' match 'signin' =&gt; 'sessions#new', :as =&gt; 'signin' match 'signout' =&gt; 'sessions#destroy', :as =&gt; 'signout' resources :customers do member do get 'add_card' post 'submit_card' end end resources :payments, :only =&gt; [:show, :new] delete 'payments/delete_recurring_payment' post 'payments/submit_non_recurring' post 'payments/submit_recurring' resources :sessions, :only =&gt; [:create, :destroy, :new] </code></pre> <p>Running 'rake routes' gives me this:</p> <pre><code> 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 </code></pre> <p>Here is where I'm stumped. When I go to localhost:3000/profile I get a routing error saying this:</p> <pre><code>No route matches {:action=&gt;"edit", :controller=&gt;"customers"} </code></pre> <p>This seems odd because there is indeed a route to 'customers#edit' due to my declaring customers as a resource. </p> <p>However, when I go to 'localhost:3000/signin' I get routed to 'customers#show' which is where I want '/profile' to route to. </p> <p>It seems like my routes are 'one off' in my routes file but I have no idea why. Any help would be much appreciated.</p> <p>Thanks</p> <p>UPDATE 1: Adding my Customers Controller</p> <pre><code> class CustomersController &lt; 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 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload