Questions tagged [rails-routing]

The component of the Ruby on Rails framework responsible for mapping between HTTP requests and application resources (including static files and controller actions).

955 questions
10
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,791
  • 5
  • 26
  • 46
10
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
  • 11,863
  • 15
  • 65
  • 88
9
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?
dotNETbeginner
  • 3,402
  • 8
  • 40
  • 57
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…
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,596
  • 17
  • 20
9
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) …
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
  • 7
  • 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
  • 13,825
  • 14
  • 51
  • 69
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…
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…
8
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
  • 8,060
  • 7
  • 32
  • 52
7
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
  • 23,101
  • 33
  • 104
  • 161
7
votes
1 answer

Rails 3 Routes: DRY members

I need to add the following member methods to a number of resources, is there a way to DRY this up? member do get :votes post :up_vote post :down_vote end In my routes.rb resources :news do resources :comments do member…
Dex
  • 11,863
  • 15
  • 65
  • 88
1 2
3
63 64