Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url helper for redirects and links #6

Open
ericgj opened this issue Jul 26, 2012 · 0 comments
Open

url helper for redirects and links #6

ericgj opened this issue Jul 26, 2012 · 0 comments

Comments

@ericgj
Copy link
Member

ericgj commented Jul 26, 2012

Maybe you can convince me I don't need such things in Cuba, but with Sinatra I use the url() AKA to() helper method quite a bit. Especially when I am mounting apps with Rack::URLMap. It lets me change the 'mount-point' without breaking the links and redirects spread all over my app. It's the equivalent of Rails' url_for without the overhead of controller classes.

I don't see how you could have such a method in Cuba very easily, given there isn't this concept of fixed top-level mount-points and the SCRIPT_NAME is adjusting all the time. I suppose in your top-level app, you could have some settings like

Cuba.settings[:mounts] = {
  admin: "admin",
  blog: "blog",
  api: "api",
  app: ""
}

And then some helpers that uses these settings like

res.redirect to_mount(:blog)               # res.redirect '/blog'
res.redirect to_mount(:app, "dashboard")  # res.redirect '/dashboard'

on mount(:admin) { }        #  on 'admin'

So then when you decide you have to re-organize or rename the mount-points, you only have to change the strings in one place.

But is there another simple alternative to using full path strings in links and redirects?

@codereading/readers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant