Atari2600
Atari2600

Reputation: 1239

Rails - match route to namespace controller

match '/submit_expense/:id' => 'expenses#submit_expense', :as => 'submit_expense'

How would I direct this to my :admin namespace? Do I have to define the match inside the namespace declaration?

Upvotes: 14

Views: 16094

Answers (3)

Tim Kozak
Tim Kozak

Reputation: 4182

You also can just use to: directive like this:

  get '/submit_expense/:id', to: 'admin/expenses#submit_expense'

Upvotes: 4

JWright
JWright

Reputation: 483

You can just use / like when you use the controller generator:

match '/submit_expense/:id' => 'admin/expenses#submit_expense', :as => 'submit_expense'

Upvotes: 28

Tom Harrison
Tom Harrison

Reputation: 14018

in routes.rb this might work...

namespace :admin do
  match '/submit_expense/:id' => 'expenses#submit_expense', :as => 'submit_expense'
end

Upvotes: 12

Related Questions