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
11
votes
1 answer
Why does rails redirect to the show action after creating?
New web developer here, and I think I may be missing some very fundamental knowledge.
Given the code
def create
@post = Post.new(post_params)
if @post.save
redirect_to @post
else
render "new"
…

user3277633
- 1,891
- 6
- 28
- 48
11
votes
3 answers
Accessing Named Routes in Rakefile
I have some named routes like this rake routes:
birthdays GET /birthdays(.:format) birthdays#index
In a rakefile I simply want to be able to call birthdays_url like I would in my view.
task :import_birthdays =>…

Dex
- 12,527
- 15
- 69
- 90
11
votes
1 answer
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"…

trevorgrayson
- 1,806
- 1
- 21
- 29
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
…

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,…

Phantomwhale
- 1,789
- 1
- 16
- 30
9
votes
3 answers
How to add parameter to rails index action/method?
I want to pass a parameter to the index action, but the I'm only getting the show action.
routes.rb:
Test1::Application.routes.draw do
resources :blog
end
blog_controller.rb:
def show
# code
end
def index
# code
end
View url…

Ben
- 25,389
- 34
- 109
- 165
9
votes
3 answers
Overriding a resource route to / (root) in Rails3: not changing the path helper?
I am quite new to Rails3, I basically created a subscribers scaffolding, I only want my app to respond to new and create actions.
So in config/routes.rb I defined:
resources :subscribers, :only => [:new, :create]
Which works this way
GET…

Tarik Ansari
- 281
- 2
- 7
9
votes
2 answers
render a 404 page on routing error in rails
I'm trying to render the integrated 404 page in rails as an exception. I tried this but still getting the routing error page:
posts_controller.rb
def destroy
if current_user.username == @post.email
@post.destroy
respond_to do |format|
format.html…

franklinexpress
- 1,149
- 14
- 44
9
votes
8 answers
Routing Error -- No route matches [POST] "/posts/new"
I'm working through the rubyonrails.org 'blog tutorial', and get this error when I try to submit a 'post' : Routing Error --No route matches [POST] "/posts/new"
I copied and pasted the code from the tutorial into my code. This should return a hash…

user2053119
- 91
- 1
- 2
- 4
9
votes
2 answers
What to test in Rails routing?
I'm curious what people consider adequate/thorough testing of routes. A guy I work with seems to want to assert every route in our routes file, no matter how standard. I feel like this is a waste of time, but maybe I'm wrong and there is some value…

bratsche
- 2,666
- 20
- 23
9
votes
3 answers
Rails controller action without a view
I just want to do a rails action without a view.
In my 'routes.rb'
resources :pictures do
member do
post 'dislike'
end
end
In my 'PictureController.rb'
this does not work
def dislike
@picture = Picture.find(params[:id])
…

Crystian Leão
- 695
- 1
- 8
- 18
8
votes
4 answers
Rails 3 w/ Devise: How to set two separate homepages based on whether the user is authenticated or not?
I am using Rails 3 and Devise to create an app where users arrive to the website and are shown a homepage containing a login and a signup form. This page has its own controller ("homepage") so it's route is
root :to => "homepage#index"
I want to…

Andrei Polmolea
- 147
- 1
- 8
8
votes
1 answer
Routing in Rails. Dots in URL
I have overwritten to_param method in my Category model
def to_param
name
end
And routes.rb
get '/:id' => 'categories#show', :as => :category
When name parameter doesn't contain any dots (foobar), all works right, but when it does…

evfwcqcg
- 15,755
- 15
- 55
- 72
8
votes
1 answer
Rails 3 link or button that executes action in controller
In RoR 3, I just want to have a link/button that activates some action/method in the controller. Specifically, if I click on a 'update_specs' link on a page, it should go to 'update_specs' method in my products controller. I've found suggestions…

heebee313
- 325
- 1
- 5
- 16
8
votes
2 answers
ActionController::RoutingError: uninitialized constant Api::V1::ApiController
I have Rails 5 API project for controlling user tasks and I have the following error but not always for the same controller and route.
ActionController::RoutingError: uninitialized constant Api::V1::ApiController
I describe you a little bit my…

Adrià Carro
- 697
- 1
- 10
- 22