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
5
votes
1 answer
Namespaced API's and resource routes
I have my API in a versioned namespace,
namespace :api do
namespace :v1 do
resources :posts
end
end
but now when I have my controller do a redirect_to @post I get a route error for Post because no routes are defined for it.
def create
…

Soup
- 1,699
- 15
- 30
5
votes
3 answers
How to create app-wide slug routing for Rails app?
I have a number of different models in the Rails app I'm working on. I've seen a number of sites use an app-wide slug routing approach. What do I mean by this?
http://example.com/nick-oneill <-- This points to a User…

Nick ONeill
- 7,341
- 10
- 47
- 61
5
votes
2 answers
How to write a redirect that uses relative_url_root if defined?
I'm currently using Ruby on Rails 3.2.8 and have this redirect in config/routes.rb:
root :to => redirect("/home/index.html")
which works fine for redirecting http://localhost:3000/ to http://localhost:3000/home/index.html in development. But in my…

Kevin Schmidt
- 2,111
- 2
- 14
- 12
5
votes
2 answers
Ruby on Rails redirect how to pass params in routes file
We recently changed the product name on our website from 'bracelets' to 'wristbands' and need to keep the old routes around for SEO purposes.
Essentially, these…

ruevaughn
- 1,319
- 1
- 17
- 48
5
votes
2 answers
Rails routing like github
I am using Rails 3.2
I want to have routing pretty much exactly like github, so:
root/(username)
root/(username)/(projectname)
root/(username)/(projectname)/issus
etc.
I am trying something like this:
resources :publishers do
resources :magazines…

Jonovono
- 3,437
- 5
- 42
- 64
4
votes
2 answers
Load routes from lib folder in full rails engine
I made a full engine and converted some plugins to work together with the engine ( I put them in lib/ ) and load them in an initializer engine.rb
This is the structure :
app
config
routes.rb
lib
plugin
config
routes.rb
In the routes in…

SteenhouwerD
- 1,819
- 1
- 16
- 22
4
votes
2 answers
Route test failing on: NoMethodError: undefined method `values' for "/the/route":String
I'm getting a failing test that I'm having great difficulty debugging.
My test case is:
it "routes to #active" do
get ("/parties/active").should route_to("parties#active")
end
My route is:
resources :parties do
get 'active', :on =>…

Ysiad Ferreiras
- 82
- 9
4
votes
1 answer
Rails Restful downloads
I want some users to be able to download data in a yaml file.
I see that you can do this with
send-file (but uses a lot of resources)
direct link_to the file in public folder (not good for me since the file is generated so the request needs to go…

dukha
- 69
- 5
4
votes
1 answer
How do I resolve these conflicting Rails routes?
I have an entry in my routes.rb that looks like this:
resources :baskets, :shallow => true, :only => :show
resource :owned, :only => [:create, :destroy]
end
get '/baskets/owned', :to => 'owners#index'
This creates routes that look like:
basket …

Michael Windham
- 53
- 3
4
votes
2 answers
Rails Routing with a parameter that contains a period
In older versions of Rails, you could have a parameter that includes a period (something typically reserved to separate it from the format) like this:
map.connect 'c/:domain.:format', :controller=>'home', :action=>'click_credit', :requirements => {…

Tom Lianza
- 4,012
- 4
- 41
- 50
4
votes
1 answer
How to change route name in Ruby on Rails
I'm working in a RoR project and i have some routes that i want to change how this route paths is displayed on the browser.
My route:
get 'campaigns/:slug' => 'campaigns#show'
Result:
http://localhost:3000/campaigns/cdlcuiaba
What i…

Henrique Navarro Marçulo
- 543
- 6
- 21
4
votes
1 answer
Devise error when using a route constraint
I'm using Devise for authentication. I have a route inside of a constraint.
When this route is hit, I get an error that Devise's variables are undefined.
routes.rb
Rails.application.routes.draw do
constraints subdomain: 'www' do
root to:…

Don P
- 60,113
- 114
- 300
- 432
4
votes
1 answer
Language Specific Routes For Static Pages in Rails 3
Application using Rails 3.2.8 with below gems
gem 'friendly_id', '~> 4.0'
gem 'globalize3',"0.3.0"
gem 'route_translator'
In controller /app/controllers/home_controller.rb
def static_pages
# page url is unique and used for finding static pages.
…

kanna
- 366
- 2
- 19
4
votes
1 answer
Rails 4 routing error for hash_for*(hash_for_path_name)
I am migrating my application from rails 2.3.18 to rails 4.0.0. My application works fine till rails 3.2.21. but when I migrate it from rails 3.2.21 to rails 4.0.0 it gives me error for hash_for* helper.
I got this error:
undefined method…

Nishant Upadhyay
- 639
- 7
- 20
4
votes
1 answer
Rails 4 force default route parameter to be included in generated URL
I'm wrestling with routing and default values for optional parameters. Given the route:
get '/product/:key(/:env(/:version))', to: 'delivery#widget_view',
defaults: { env: 'live' }, as: :product_view
I understand if I give it a version,…

mr_than
- 380
- 1
- 2
- 10