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
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
  • 20,727
  • 21
  • 94
  • 138
7
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,079
  • 12
  • 42
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,271
  • 6
  • 18
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
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
  • 1,645
  • 1
  • 13
  • 33
6
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
  • 63
  • 1
  • 4
6
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
  • 23,382
  • 26
  • 107
  • 175
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
  • 9,957
  • 2
  • 29
  • 55
6
votes
0 answers

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,112
  • 2
  • 23
  • 35
6
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
  • 9,810
  • 9
  • 54
  • 77
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
  • 10,195
  • 24
  • 72
  • 124
6
votes
1 answer

Rails 4 routing: using namespaces with dynamic segments

When discussing Routing using Dynamic Segments, the Ruby on Rails Guides (v4.0.1) say "You can't use :namespace or :module with a :controller path segment." They go on to suggest: "if you need to do this then use a constraint on :controller that…
RobJ
  • 129
  • 9
6
votes
3 answers

Rails routing: format constraints when none is specified

For Reasons™, I want to have one controller handle html requests and another handle json api requests. I've got this in my routes: scope module: :api, as: :api do constraints format: :json do resources :users end end constraints format:…
Chris Keele
  • 3,138
  • 3
  • 27
  • 51
6
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
  • 25,081
  • 21
  • 107
  • 188
5
votes
1 answer

How to make Rails route to response for the font files (eot)?

In my rails(2.x) application. I want to use custom font in my view. So that I added the font files in public under fonts folder. When I try to get the fonts in url or via application, it through routing error. I guess rails routes not able to…
Jak
  • 2,153
  • 17
  • 29