Rails 5 - How do I prevent Rails from adding locale to a URL on constructed paths?












0















After upgrading to Rails 5.2, (edit: using "5.2.0.rc1") I now have ?locale=en being added to my urls when I use a path constructed from path_helper (like login_path). How do I stop Rails from adding the locale to my urls? I don't need them, ever.



My controller:



```
#home_controller.rb



def index
redirect_to login_path
end


```



Application.rb



```



require_relative 'boot'

require 'rails/all'

Bundler.require(*Rails.groups)

module MyApp
class Application < Rails::Application
config.assets.initialize_on_precompile = false

config.generators do |g|
g.fixture_replacement :rspec
g.fixture_replacement :factory_bot
end
end
end


```



What Happens:



It redirects me to localhost:3000/login?locale=en










share|improve this question

























  • What does your application.rb filre look like?

    – Dan Rubio
    Nov 18 '18 at 2:37











  • added to question

    – Starcat
    Nov 18 '18 at 2:41











  • Is this all that's in the file? I'm looking for something as shown here. guides.rubyonrails.org/configuring.html#configuring-i18n Do you have anything like that? Especially something like config.i18n.default_locale

    – Dan Rubio
    Nov 18 '18 at 2:46













  • Yeah, that's all thats in the file :/

    – Starcat
    Nov 18 '18 at 2:55











  • I'm sensing it's something with the path_helper in this version of rails - when I hardcode the redirect as string"/login", it's all good. but when I use login_path it adds the locale

    – Starcat
    Nov 18 '18 at 2:56
















0















After upgrading to Rails 5.2, (edit: using "5.2.0.rc1") I now have ?locale=en being added to my urls when I use a path constructed from path_helper (like login_path). How do I stop Rails from adding the locale to my urls? I don't need them, ever.



My controller:



```
#home_controller.rb



def index
redirect_to login_path
end


```



Application.rb



```



require_relative 'boot'

require 'rails/all'

Bundler.require(*Rails.groups)

module MyApp
class Application < Rails::Application
config.assets.initialize_on_precompile = false

config.generators do |g|
g.fixture_replacement :rspec
g.fixture_replacement :factory_bot
end
end
end


```



What Happens:



It redirects me to localhost:3000/login?locale=en










share|improve this question

























  • What does your application.rb filre look like?

    – Dan Rubio
    Nov 18 '18 at 2:37











  • added to question

    – Starcat
    Nov 18 '18 at 2:41











  • Is this all that's in the file? I'm looking for something as shown here. guides.rubyonrails.org/configuring.html#configuring-i18n Do you have anything like that? Especially something like config.i18n.default_locale

    – Dan Rubio
    Nov 18 '18 at 2:46













  • Yeah, that's all thats in the file :/

    – Starcat
    Nov 18 '18 at 2:55











  • I'm sensing it's something with the path_helper in this version of rails - when I hardcode the redirect as string"/login", it's all good. but when I use login_path it adds the locale

    – Starcat
    Nov 18 '18 at 2:56














0












0








0








After upgrading to Rails 5.2, (edit: using "5.2.0.rc1") I now have ?locale=en being added to my urls when I use a path constructed from path_helper (like login_path). How do I stop Rails from adding the locale to my urls? I don't need them, ever.



My controller:



```
#home_controller.rb



def index
redirect_to login_path
end


```



Application.rb



```



require_relative 'boot'

require 'rails/all'

Bundler.require(*Rails.groups)

module MyApp
class Application < Rails::Application
config.assets.initialize_on_precompile = false

config.generators do |g|
g.fixture_replacement :rspec
g.fixture_replacement :factory_bot
end
end
end


```



What Happens:



It redirects me to localhost:3000/login?locale=en










share|improve this question
















After upgrading to Rails 5.2, (edit: using "5.2.0.rc1") I now have ?locale=en being added to my urls when I use a path constructed from path_helper (like login_path). How do I stop Rails from adding the locale to my urls? I don't need them, ever.



My controller:



```
#home_controller.rb



def index
redirect_to login_path
end


```



Application.rb



```



require_relative 'boot'

require 'rails/all'

Bundler.require(*Rails.groups)

module MyApp
class Application < Rails::Application
config.assets.initialize_on_precompile = false

config.generators do |g|
g.fixture_replacement :rspec
g.fixture_replacement :factory_bot
end
end
end


```



What Happens:



It redirects me to localhost:3000/login?locale=en







ruby-on-rails ruby-on-rails-5






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 '18 at 15:22







Starcat

















asked Nov 18 '18 at 0:29









StarcatStarcat

587




587













  • What does your application.rb filre look like?

    – Dan Rubio
    Nov 18 '18 at 2:37











  • added to question

    – Starcat
    Nov 18 '18 at 2:41











  • Is this all that's in the file? I'm looking for something as shown here. guides.rubyonrails.org/configuring.html#configuring-i18n Do you have anything like that? Especially something like config.i18n.default_locale

    – Dan Rubio
    Nov 18 '18 at 2:46













  • Yeah, that's all thats in the file :/

    – Starcat
    Nov 18 '18 at 2:55











  • I'm sensing it's something with the path_helper in this version of rails - when I hardcode the redirect as string"/login", it's all good. but when I use login_path it adds the locale

    – Starcat
    Nov 18 '18 at 2:56



















  • What does your application.rb filre look like?

    – Dan Rubio
    Nov 18 '18 at 2:37











  • added to question

    – Starcat
    Nov 18 '18 at 2:41











  • Is this all that's in the file? I'm looking for something as shown here. guides.rubyonrails.org/configuring.html#configuring-i18n Do you have anything like that? Especially something like config.i18n.default_locale

    – Dan Rubio
    Nov 18 '18 at 2:46













  • Yeah, that's all thats in the file :/

    – Starcat
    Nov 18 '18 at 2:55











  • I'm sensing it's something with the path_helper in this version of rails - when I hardcode the redirect as string"/login", it's all good. but when I use login_path it adds the locale

    – Starcat
    Nov 18 '18 at 2:56

















What does your application.rb filre look like?

– Dan Rubio
Nov 18 '18 at 2:37





What does your application.rb filre look like?

– Dan Rubio
Nov 18 '18 at 2:37













added to question

– Starcat
Nov 18 '18 at 2:41





added to question

– Starcat
Nov 18 '18 at 2:41













Is this all that's in the file? I'm looking for something as shown here. guides.rubyonrails.org/configuring.html#configuring-i18n Do you have anything like that? Especially something like config.i18n.default_locale

– Dan Rubio
Nov 18 '18 at 2:46







Is this all that's in the file? I'm looking for something as shown here. guides.rubyonrails.org/configuring.html#configuring-i18n Do you have anything like that? Especially something like config.i18n.default_locale

– Dan Rubio
Nov 18 '18 at 2:46















Yeah, that's all thats in the file :/

– Starcat
Nov 18 '18 at 2:55





Yeah, that's all thats in the file :/

– Starcat
Nov 18 '18 at 2:55













I'm sensing it's something with the path_helper in this version of rails - when I hardcode the redirect as string"/login", it's all good. but when I use login_path it adds the locale

– Starcat
Nov 18 '18 at 2:56





I'm sensing it's something with the path_helper in this version of rails - when I hardcode the redirect as string"/login", it's all good. but when I use login_path it adds the locale

– Starcat
Nov 18 '18 at 2:56












1 Answer
1






active

oldest

votes


















0














It seems like somewhere along the line in Rails 5 the path_helper regressed to no longer omit optional params like locale when constructing URLs. Only thing to do is wait for a PR to fix it. Looks like a lot have been made but unclear if they have been merged or if the fix exists in 5.2.1



https://github.com/rails/rails/pull/32526



https://github.com/rails/rails/pull/32382



https://github.com/rails/rails/pull/33846






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53356842%2frails-5-how-do-i-prevent-rails-from-adding-locale-to-a-url-on-constructed-path%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    It seems like somewhere along the line in Rails 5 the path_helper regressed to no longer omit optional params like locale when constructing URLs. Only thing to do is wait for a PR to fix it. Looks like a lot have been made but unclear if they have been merged or if the fix exists in 5.2.1



    https://github.com/rails/rails/pull/32526



    https://github.com/rails/rails/pull/32382



    https://github.com/rails/rails/pull/33846






    share|improve this answer




























      0














      It seems like somewhere along the line in Rails 5 the path_helper regressed to no longer omit optional params like locale when constructing URLs. Only thing to do is wait for a PR to fix it. Looks like a lot have been made but unclear if they have been merged or if the fix exists in 5.2.1



      https://github.com/rails/rails/pull/32526



      https://github.com/rails/rails/pull/32382



      https://github.com/rails/rails/pull/33846






      share|improve this answer


























        0












        0








        0







        It seems like somewhere along the line in Rails 5 the path_helper regressed to no longer omit optional params like locale when constructing URLs. Only thing to do is wait for a PR to fix it. Looks like a lot have been made but unclear if they have been merged or if the fix exists in 5.2.1



        https://github.com/rails/rails/pull/32526



        https://github.com/rails/rails/pull/32382



        https://github.com/rails/rails/pull/33846






        share|improve this answer













        It seems like somewhere along the line in Rails 5 the path_helper regressed to no longer omit optional params like locale when constructing URLs. Only thing to do is wait for a PR to fix it. Looks like a lot have been made but unclear if they have been merged or if the fix exists in 5.2.1



        https://github.com/rails/rails/pull/32526



        https://github.com/rails/rails/pull/32382



        https://github.com/rails/rails/pull/33846







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 18 '18 at 15:21









        StarcatStarcat

        587




        587






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53356842%2frails-5-how-do-i-prevent-rails-from-adding-locale-to-a-url-on-constructed-path%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Academy of Television Arts & Sciences

            L'Équipe

            1995 France bombings