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).

969 questions
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
  • 12,527
  • 15
  • 69
  • 90
7
votes
2 answers

Creating an Admin directory in Rails

I've been developing the CMS backend for a website for a few weeks now. The idea is to craft everything in the backend first so that it can manage the database and information that will be displayed on the main website. As of now, I currently have…
matsko
  • 21,895
  • 21
  • 102
  • 144
7
votes
1 answer

Ruby on Rails choosing wrong controller action

Today I came across some strange (and very inconvenient) Ruby on Rails behavior that even persistent combing of the net did not yield a satisfying answer to. Note: I translated the method and route names to be easier to read in English, and hope I…
Mike
  • 73
  • 1
  • 4
7
votes
1 answer

Why does mounting a route in Rails fail with "uninitialized constant API"?

I am working on an app that includes an API that is using the grape gem. Here is my Root Class: module API class Root < Grape::API rescue_from :all do |e| Rack::Response.new( [ "Error: #{e.message}" ], 500, {…
dennismonsewicz
  • 25,132
  • 33
  • 116
  • 189
7
votes
2 answers

Rails Routes - slash character vs hash character

In urls and rails routing, what is the difference between using a slash character vs a pound sign (hash sign) character? These work get "/static_pages/about" get 'about', to: 'static_pages#about', as: :about These don't get…
ahnbizcad
  • 10,491
  • 9
  • 59
  • 85
7
votes
1 answer

i18n Routing To Mounted Engine - Ignoring locale

I have an application (my_test_app) with working i18n support built. Currently, there are two language files available, FR & EN, and if I toggle back and forth between them, everything works as I expect to see it for non-engine functions such as…
MichelV69
  • 1,247
  • 6
  • 18
7
votes
1 answer

Adding prefix to a named route helper under namespace

This is how a common namespace looks like. namespace :admin do resources :posts end And it creates a named route like this one; new_admin_post_path Here's my question; how can I add a prefix (like "new" in this example) to a named route under…
Eren CAY
  • 686
  • 1
  • 7
  • 17
7
votes
3 answers

How to include routing in ApplicationHelper Spec when running trough Spork?

I have an rspec spec: require "spec_helper" describe ApplicationHelper do describe "#link_to_cart" do it 'should be a link to the cart' do helper.link_to_cart.should match /.*href="\/cart".*/ end end end And the…
berkes
  • 26,996
  • 27
  • 115
  • 206
7
votes
1 answer

Ruby on Rails - passing params into 301 redirect in routes.rb

I want to change my existing 'game' routing inside routes.rb, but because of SEO I need also to setup 301 redirect for old links. My old routing: match 'games/:permalink/:id/(:page)' => 'games#show' New routing: match 'gierki/:permalink/(:page)' =>…
Arti
  • 407
  • 5
  • 15
6
votes
5 answers

Routing for sessions#destroy action

I'm linking to the destroy action for the Sessions controller like this: <%= link_to "Sign out", session_path, method: :delete %> Routes.rb: resources :sessions, only: [:new, :create, :destroy] Rails complains about the link above: No route…
Fellow Stranger
  • 32,129
  • 35
  • 168
  • 232
6
votes
1 answer

Rails NameError uninitialized constant (Model and Namespace Collision)

I have a model named Organization. It is defined in app/models/organization.rb class Organization < ActiveRecord::Base ... code end I have a controller named Admin::Organization::ActivitiesController. It is defined in…
CodeSmith
  • 2,133
  • 1
  • 20
  • 43
6
votes
3 answers

Check for the existing of a header attribute in rails before invoking an action

I am building an API in rails 4. Before invoking an action, I am trying first to check whether an attribute exist in the http header. Is there a way to do that instead of checking each in all actions of the controllers. The rails documentation…
delpha
  • 931
  • 1
  • 8
  • 23
6
votes
1 answer

Setting a default namespace for URL Helpers in Rails 4?

I have a Rails 4 app where all controllers and views are divided into two namespaces, an agent-facing backend and a customer-facing frontend: MyApp::Application.routes.draw do constraints subdomain: "admin" do namespace :backend do …
janfoeh
  • 10,243
  • 2
  • 31
  • 56
6
votes
1 answer

Redirect all routes in a path to another path and keep rest of the URL intact

I want to rename a resource in a Rails app, and have all the old routes redirect to the new ones for backwards compatibility with old links. For example, rename 'user' to 'member' and have all arbitrary route such as…
Nicolas
  • 2,297
  • 3
  • 28
  • 40
6
votes
3 answers

How to set default format for routing in Rails?

There is the following code for routing: resources :orders, only: [:create], defaults: { format: 'json' } resources :users, only: [:create, :update], defaults: { format: 'json' } resources :delivery_types, only: [:index], defaults: { format:…
malcoauri
  • 11,904
  • 28
  • 82
  • 137