Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prepend path prefix to all rails routes

I have a setup where nginx serves a rails application inside a specific subfolder

eg. http://myserver/railsapp/ and everything inside gets proxied to rails, if the first subfolder is different, it servers static files from another folder.

I haven't been able to find how to specify this behaviour in rails in an intelligent way. I mean, what I want is to specify an option like Rails.server_prefix = /railsapp so that all the routes get prepended automagically, both on the incoming requests and on the generated links.

like image 821
Sergio Campamá Avatar asked Dec 10 '11 20:12

Sergio Campamá


People also ask

How do I see all routes in Rails?

TIP: If you ever want to list all the routes of your application you can use rails routes on your terminal and if you want to list routes of a specific resource, you can use rails routes | grep hotel . This will list all the routes of Hotel.

What is the difference between resources and resource in Rails?

Difference between singular resource and resources in Rails routes. So far, we have been using resources to declare a resource. Rails also lets us declare a singular version of it using resource. Rails recommends us to use singular resource when we do not have an identifier.

What are RESTful routes in Rails?

In Rails, a RESTful route provides a mapping between HTTP verbs, controller actions, and (implicitly) CRUD operations in a database. A single entry in the routing file, such as. map.resources :photos. creates seven different routes in your application: HTTP verb.


1 Answers

You probably want to use the router's scope method with the :path argument:

Rails.application.routes do
  scope(:path => '/railsapp') do
    # the rest of your routes go here
  end
end

See the docs for more info.

like image 198
phiggy Avatar answered Sep 28 '22 17:09

phiggy