How to add trailing_slash to all urls without Rails 4?

I tried adding this to application.rb

config.action_controller.default_url_options = { :trailing_slash => true }

as well :trailing_slash => trueas routes. rb

match '/download', to: 'welcome#download', via: 'get', :trailing_slash => true

But it doesn't seem to work. I searched the 4.0 doc rails but could not find the relevant information. What am I missing here?

Update:

I tried adding

Rails.application.default_url_options[:trailing_slash] = true

in filter_parameter_logging.rb, since this is the only place in the whole project where I could find Rails.application.*, but it does not work. I found a line here among the releases , and I'm using 4.0.4. Can I add this in the wrong place? And I restarted the server before re-checking.

And sorry for the simple question, but from what I compiled is not trailing_slashwhich should be reflected in the browser URL, if not in the first place? Because this is what I need to go with the story.

+4
4

, :trailing_slash => true.

, , / . .

- .

-t21 > uri, /download /download/, HTTP- nginx, - :

rewrite ^([^.\?]*[^/])$ $1/ permanent;

:trailing_slash => true , /URL uri ( ).

+9

Trailing_slash / page/, /page.

.

match 'download/', to: 'welcome#download', via: 'get', :trailing_slash => true

, trailing_slash => true link_to.

link_to 'Downloads', downloads_path(:trailing_slash => true)

Rails 3, Rails 4.

. fooobar.com/questions/432014/....

+2

rails 4.0.2

routes.rb

       get 'admin/update_price_qty' => 'admin#update_price_qty', :trailing_slash => true,:as  => "price"

: -

     irb(main):003:0* app.price_path
     => "/admin/update_price_qty/"

routes.rb

   match '/download', to: 'welcome#index', via: 'get', :trailing_slash => true,:as => "welcome_price"

: -

   `irb(main):002:0> app.welcome_price_path
    => "/download/"`

application.rb

config.action_controller.default_url_options = { :trailing_slash => true }

.

+1

config/application.rb:

config.action_controller.default_url_options = { trailing_slash: true }

, Rails , / :

class ApplicationController
  def index
    download_path # returns "/download/"
  end
end

module PathHelper
  def path
    download_path # returns "/download/"
  end
end

If you need to use path helpers outside of the controllers and helpers, you need to include Rails.application.routes.url_helpers, but apparently this ignores the trailing_slash configuration above:

class SomeClass
  include Rails.application.routes.url_helpers

  def path
    download_path # returns "/download"
  end
end

In this case, you should add { trailing_slash: true }as a parameter:

class SomeClass
  include Rails.application.routes.url_helpers

  def path
    download_path(trailing_slash: true) # returns "/download/"
  end
end
0
source

Source: https://habr.com/ru/post/1536698/


All Articles