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]
955 questions
20
votes
3 answers
How to change a route name rails 4
I changed the routing of posts#index to match blog and I now get /blog in the URL which I was trying to accomplish.
I've tried several different things to get my actual blog post which the route currently looks something like /posts/this-is-a-test…
![](../../users/profiles/613888.webp)
Kevin Dark
- 1,969
- 5
- 20
- 23
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?
![](../../users/profiles/429649.webp)
Tamik Soziev
- 12,908
- 5
- 39
- 53
17
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…
![](../../users/profiles/117603.webp)
Mike Trpcic
- 23,821
- 7
- 71
- 111
17
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…
![](../../users/profiles/1486158.webp)
sidj
- 405
- 1
- 3
- 10
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…
![](../../users/profiles/23368.webp)
Daniel Rikowski
- 66,219
- 52
- 237
- 318
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…
![](../../users/profiles/1614737.webp)
Bishma Stornelli
- 2,413
- 3
- 19
- 28
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,
…
![](../../users/profiles/1708330.webp)
kanna
- 366
- 2
- 18
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…
![](../../users/profiles/402494.webp)
Kyle d'Oliveira
- 6,052
- 1
- 22
- 32
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…
![](../../users/profiles/571111.webp)
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…
![](../../users/profiles/2670462.webp)
peeyush singla
- 507
- 1
- 7
- 19
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…
![](../../users/profiles/63761.webp)
Meltemi
- 36,348
- 48
- 182
- 274
11
votes
2 answers
Enforce trailing slash in Rails Routing
Adding a trailing slash in your links is easy enough with {:trailing_slash => true}, but this doesn't account for if a user types in a non-slashed url. Is there a way to enforce trailing slashes via redirects in the router?
get "/:controller/:id"…
![](../../users/profiles/965161.webp)
trevorgrayson
- 1,719
- 20
- 28
11
votes
2 answers
Rails Routing Error? 'No route matches'
So I keep running into the following error:
No route matches {:action=>"show", :controller=>"users"}
I tried running rake routes and I can see that the route exists:
user GET /users/:id(.:format) users#show
…
![](../../users/profiles/1497531.webp)
user1497531
- 231
- 1
- 3
- 6
10
votes
2 answers
How to write routing when resource model name does not match path or controller
I've got a model called ImplicitTest. It's called this as having a Ruby object called Test just breaks a lot of things in Rails.
However, I still want to expose it as a RESTful resource as test (e.g. /tests, /test/1/edit and so forth). Furthermore,…
![](../../users/profiles/82663.webp)
Phantomwhale
- 1,540
- 1
- 14
- 28
10
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…
![](../../users/profiles/2026098.webp)
Elise
- 4,754
- 4
- 32
- 46