Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 833
pwz2000 Avatar asked Feb 28 '14 19:02

pwz2000


1 Answers

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)

like image 111
Richard Peck Avatar answered Sep 22 '22 06:09

Richard Peck