Coder Social home page Coder Social logo

Comments (5)

Steffeng5 avatar Steffeng5 commented on July 18, 2024

I have the same problem: I want to deploy my application to a subfolder, but the routes are specified to the root folder. Is there anything i can do?

from routing-filter.

AndrewRadev avatar AndrewRadev commented on July 18, 2024

If you're having issues with locales, you should be able to use standard rails 3 routing to do the trick.

You see, at the time, I wanted to generate routes like this:

scope "(:locale)", :locale => /en|de/ do
  resources :posts
  resources :categories
end

This would mean that I could go to "/en/posts" or "/de/posts" depending on the language and "/posts" would dispatch to "/en/posts" by default.

The problem was that, since the ":locale" part was optional, the standard rails helpers wouldn't work properly. For example, post_path(@post) would simply break. This is why I tried to use this plugin instead. Since then, it appears that this has been resolved somehow within rails. I'm not sure which version fixes that, since I never bothered to check, but the latest stable, 3.0.7, should be okay -- you could just remove this plugin and try it out with standard routing. If you haven't seen it, take a look at the article in the rails guides: http://guides.rubyonrails.org/i18n.html#setting-the-locale-from-the-url-params

If you're not using rails 3, though, I'm afraid I can't be of any help.

from routing-filter.

Steffeng5 avatar Steffeng5 commented on July 18, 2024

Thanks for your help. The last time I try this solution, i had the same problems with the helper methods. I solved my problem with editing the locale filter in that way:

def prepend_segment!(result, segment)
    url = result.is_a?(Array) ? result.first : result
    url.sub!(%r(^(http.?://[^/]*)?(.*))) {
        t1 = $1
        t2 = $2
        if t2.to_s.start_with? "/portal"
               t1 = t1.to_s ? t1.to_s+"/portal" :  "/portal"
               t2 = t2[7..t2.length-1]
        end

        "#{t1}/#{segment}#{t2 == '/' ? '' : t2}"
        }
end

from routing-filter.

AndrewRadev avatar AndrewRadev commented on July 18, 2024

Yes, that seems like it should work just fine for your particular app. Still, I'd recommend updating rails and trying out the standard routing again, just in case. You can always revert it later if it breaks :).

from routing-filter.

priidikvaikla avatar priidikvaikla commented on July 18, 2024

I have related problem where other gems expect that Rails root_url is ending with slash. While using routing-filter root_url is not ending with slash anymore. This is caused by this block "{$2 == '/' ? '' : $2}". Quick fix would be remove the check and let the line be like this: "url.sub!(%r(^(http.?://[^/])?(.))) { "#{$1}/#{segment}#{$2}" }" but then extension filter tests would fail.

from routing-filter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.