pwz2000
pwz2000

Reputation: 1395

ActionController::UrlGenerationError: No route matches

I am receiving a no route matches error from the line <%= link_to "Ask User Out", askout_user_message_path(@user), :class => "button" %>.

This used to work before I added a gem but now it stopped working. I tried moving under collection but I get no luck with that as that's where it used to be.

Routes:

 resources :users do |user|

 resources :messages do
   member do
     post :new
     get 'askout', action: 'askout'
   end
 end
  collection do
     get :trashbin
     post :empty_trash

end
 end

 resources :conversations do
   member do
     post :reply
     post :trash
     post :untrash
   end
 end

Old Routes:

 resources :users do |user|

    resources :messages do
      collection do
        post 'delete_multiple'
        get 'askout', action: 'askout'
        get 'reply', action: 'reply'
      end
    end
  end

My routes changed as I added mailboxer gem.

Upvotes: 6

Views: 18158

Answers (1)

Richard Peck
Richard Peck

Reputation: 76774

You'd be better doing this:

   #config/routes.rb
   resources :users do
     resources :messages do
       member do
         post :new
         get :askout
       end
     end
     collection do
         get :trashbin
         post :empty_trash
      end
   end

This will give you:

users/1/messages/5/askout

What I think you want:

   #config/routes.rb
   resources :users do
     resources :messages do
       post :new
       collection do
         get :askout
       end
     end
     collection do
         get :trashbin
         post :empty_trash
      end
   end

This will give you:

users/2/messages/askout

The path helper will be as determined in the rake routes view -- you should look at it to get an idea as to what your route is called (allowing you to write it accordingly)

Upvotes: 5

Related Questions