The component of the Ruby on Rails framework responsible for mapping between HTTP requests and application resources (including static files and controller actions).
Questions tagged [rails-routing]
969 questions
20
votes
4 answers
How can I create a Rails 3 route that will match all requests and direct to one resource / page?
I have a rails app (Rails 3.0) that I need to temporarily take out of service. While this is in effect, I want to create a new route that will direct all requests to a single piece of static content. I have a controller set up to serve my static…

Nick
- 959
- 1
- 9
- 14
20
votes
2 answers
Rails Routes based on condition
I have three roles: Instuctor, Student, Admin and each have controllers with a "home" view.
so this works fine,
get "instructor/home", :to => "instructor#home"
get "student/home", :to => "student#home"
get "admin/home", :to => "admin#home"
I want…

sidj
- 525
- 1
- 5
- 12
18
votes
1 answer
Do I need a slash in front of rails route
I have the following url structure in rails routes:
match '/financial-dictionary/:letter' => 'learning_center#dictionary', :as => :lc_dictionary
Do i need a leading slash in front of "financial-dictionary"? What will happen if i remove it?

Tamik Soziev
- 14,307
- 5
- 43
- 55
18
votes
1 answer
How to test route constraints with rspec
I'm working on an application that will be primarily served as an API (other than a few minor views, such as session/registration, which will be "standard"). I like the approach that was finalized in Railscast #350: Versioning an API, and so…

Mike Trpcic
- 25,305
- 8
- 78
- 114
17
votes
3 answers
when does rails looks for Index method and when for show method in controller
I'm new to Rails and I have been following a tutorial.
I have been fiddling around with routes.rb and now in total confusion about when it looks for show method and when for index method if not explicitly mentioned?

techBeginner
- 3,792
- 11
- 43
- 59
16
votes
3 answers
What's the difference between :new, :collection and :member routes?
I've read the documentation, but I'm still not sure I understand everything.
Especially why there's a :new parameter. As far as I understand, it could be replaced with the :collection parameter.
So what's the difference between those three types of…

Daniel Rikowski
- 71,375
- 57
- 251
- 329
16
votes
2 answers
How to declare a nested resource in activeadmin?
I have a resource called User and another one called Order.
I want Order to be nested inside Users so I can have these…

Bishma Stornelli
- 2,539
- 4
- 22
- 30
15
votes
1 answer
Redirect To Same Page In New Domain after Locale changes in Rails 3
Application using Rails 3.2.8 with below gems
gem 'friendly_id', '~> 4.0'
gem 'route_translator'
In /config/initializers/i18n.rb
TLD_LOCALES = {
"com" => :en,
"jobs" => :en,
"net" => :en,
"in" => :en,
"de" => :de,
"ch" => :de,
…

kanna
- 366
- 2
- 19
13
votes
5 answers
Engine routes in Application Controller
I have a before_filter hook in my main app's application controller that does something like: (It doesn't just put a link in the flash, there is a message, but it isn't relevant to the question, it just accesses the route in the method)
class…

Kyle d'Oliveira
- 6,382
- 1
- 27
- 33
12
votes
3 answers
grouping controller in subdirectories for nested resources
I would like to organize my controllers in subdirectories. Here is an example:
routes.rb:
resources :locations do
resources :users
end
I would like to put my controller in the appropriate…

fluxsaas
- 997
- 2
- 11
- 27
12
votes
3 answers
How to get the current route in rails
I am building some rails sample application in which I am having two models User and Projects. Association between both is user has_many projects. Now the question is I am willing to provide some drop down for user's projects on top and if some one…

peeyush singla
- 557
- 2
- 8
- 20
12
votes
2 answers
Getting Rails Nested Resources to Route to correct nested Controllers
In Rails 3.2.11, I have the following route definitions
resources :foos do
resources :bars
resources :bangs, :controller => 'foos/bangs'
end
which result in the following routes
foo_bars GET /foos/:foo_id/bars(.:format) …

CITguy
- 198
- 1
- 2
- 9
12
votes
3 answers
Rails route: define root to namespace
I've got 2 controllers:
app/
/controllers
posts_controllers.rb
/mobile
posts_controllers.rb
and my routes.rb looks like this:
root :to => "posts#index"
resources :posts
namespace :mobile do
root :to => "posts#index"
…

Said Kaldybaev
- 9,380
- 8
- 36
- 53
11
votes
6 answers
Rails 3 link_to (:method => :delete) not working
I'm having trouble with my verbs in Rails...
viewing a page for a resource (Dog) which has_many (Fleas). Embedded in dog's show.html.haml is a call to render @dog.fleas which automatically(?) finds & uses the template in "fleas/_flea.html.haml" to…

Meltemi
- 37,979
- 50
- 195
- 293
11
votes
2 answers
Rails routes: redirect an entire resource
I know about redirecting a specific route:
put 'users/:user_id', to: redirect('/api/v1/users/:user_id')
How would I apply the redirect to all routes generated by resources? Looking for something like
resources :users, to: redirect('/api/v1')
I can…

Elise
- 5,086
- 4
- 36
- 51