...the correct protocol. Caveats: You need to harden your server setup to forbid the routing of a request with the HOST header to an application server, that serves requests under...

TL;DR There are three dimensions you can control when scoping routes: path helpers, URL segments, and controller/view module. scope module: 'module', path: 'url_prefix', as: 'path_helper_name' do...

...work with resources as well, e.g. resources :examples, path: 'demonstration' Two macros for namespacing routes Rails offers two macros for namespacing routes. As its name suggests, namespace is the tool...

...you have any class which requires access to some path methods generated by your routes. Even though you could technically include Rails.application.routes.url_helpers, this may include way too many methods...

...s ActiveRecord loading or URL generation lines. Option 2: Completely silencing logging for ActiveStorage routes If you want to silence ActiveStorage requests completely, you need to replace the Rails::Rack...

...is. We basically just want a version of it that silences logging for ActiveStorage routes, so we can write it as follows. class RackLoggerWithSilencedActiveStorageRoutes < Rails::Rack::Logger def call(env...

makandra dev
medium.com

In Ruby on Rails, all the routes of a given application can be found within the config/routes.rb file. You add more and more routes in this file as your project...

...s why it’s important to find a way to order and maintain your routes. See: Clean your Rails routes: grouping Sometimes the routes.rb grows very fast and each line...

...What seems like a simple requirement is a little awkward to configure in your routes. Obviously the report should be a singleton resource, but how can we nest it into...

...resources :projects, only: :show do resource :report, only: :show end If we defined the routes above we would get a report for each project, instead of one report across all...

...you would like to generate a path or URL string from an array of route components just as form_for does, you can use polymorphic_path or polymorphic_url:

...url([:admin, @user]) # "/admin/users/55" :action - Specifies the action prefix for the named route: :new or :edit. Default is no prefix. polymorphic_url([@user, Post], :action => :new) # "/users/45/posts/new" #same as

makandra dev

...Angular app has some decent complexity, it will not be easy to use UI Router straight away. Here are some hints on how to get around. Accessing the UI Router...

...to those images may end up on your application, e.g. if a catch-all route is defined that leads to a controller doing some heavy lifting. On pages with lots...

...this slows down development response times. You can fix that by defining a Rails route like this: if Rails.env.development? scope format: true, constraints: { format: /jpg|png|gif/ } do get '/*anything...

...determine the view path from this option, too. That means the following code in routes.rb … resources :users do resource :profile, controller: 'users/profiles' #[1] end … makes Rails expect the following directory...

stackoverflow.com

If you want to have routes that are only available in tests (e.g. for testing obscure redirects), you can use the with_routing helper -- but that one destroys existing routes...

...break a specs that require them to work. To keep both "regular" and test routes, do this: class MyApplicationController < ActionController::Base def show render text: 'Welcome to my application'

makandra dev

The following initializer provides an :alias => "my_route_name" option to restful routes in your route.rb. This simply makes the same route also available under a different ..._path / ..._url helpers...

You won't usually have to do this. It's OK to route all formats to a controller, and let the controller decide to which format it wants to respond...

...Should you for some reason want to define a route that only responds to a given format, here is how you do it: Rails 3 match 'sitemap.xml' => 'feeds#sitemap', :constraints...

markembling.info

...always be better off using simple pluralizable resources. Rails automatically creates path names for routes defined via the resource method. When you put resource 'user' into config/routes.rb, you can call...

...remember it as desired format and forward the rest of the request to the routing engine. Since we're making .xml part of the match, it is not available for...

...not served on /, but on a different url (say /admin), links generated with ui-router will not work when you open them in a new tab. Fix this by adding...

makandra dev

You cannot say this because url_for only takes one parameter: url_for(@deal, :tab => 'general') # won't work

blog.peepcode.com

The Rails router has been written and rewritten at least four times2, including a recent rewrite for the upcoming Rails 3. The syntax is now more concise. But never mind...

...Power.new(Current.user) } require_power_check power :direct_uploads end Now map the direct_uploads route used by your frontend controller (over the data-direct-upload-url) to this custom controller...

Rails.application.routes.draw do scope ActiveStorage.routes_prefix do post "/direct_uploads" => "custom_direct_uploads#create", as: :rails_direct_uploads end end Note that by default you usually set a direct-upload attribute...

...this add the following code to spec/requests/default_etag_spec.rb. You may need to adjust the let :route_with_tokens so it returns a good route within your app. describe 'Default ETag' do...

...let :route_with_tokens do # This route should render a full layout and a form so it has a CSP nonce and CSRF tokens. # The controller action should rely on...

Rails' url_for is useful for generating routes from a Hash, but can lead to an open redirect vulnerability. Your application's generated route methods with a _url suffix are...

...you want to redirect and keep all parameters, we strongly recommend redirecting from your routes. When you need to use url_for, use request.path_parameters and request.query_parameters as described...

...Rails < 6.1 when delivering responses for different MIME-types. Say you have an arbitrary route in your Rails application that is able to respond with regular HTML and JSON. By...

...from the specified Accept header. This means that the first request made to the route is cached, regardless of the desired response format. While this works as long as only...

...Language HTTP header. Note that even the best default never replaces a language switcher. Routes and URLs You might want to localize route components so e.g. /messages/new becomes /nachrichten/neu. You...

...can index each version separately. E.g. there should be a /en/users/5003 and a /de/users/5003. The routing-filter gem comes with a filter that helps you with that. You must also...