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 to generate absolute URL #751

Closed
pke opened this Issue Jan 10, 2012 · 17 comments

Comments

Projects
None yet
@pke

pke commented Jan 10, 2012

Currently the URL helper generates relative URLs. Is there a way to generate a fully qualified URL?

@joshbuddy

This comment has been minimized.

Show comment
Hide comment
@joshbuddy

joshbuddy Jan 10, 2012

Contributor

yeah, I'm working on this now.

Contributor

joshbuddy commented Jan 10, 2012

yeah, I'm working on this now.

@pke

This comment has been minimized.

Show comment
Hide comment
@pke

pke Jan 10, 2012

Great, thanks!

pke commented Jan 10, 2012

Great, thanks!

@ghost ghost assigned joshbuddy Jan 11, 2012

@rainchen

This comment has been minimized.

Show comment
Hide comment
@rainchen

rainchen Mar 1, 2012

any progress?

rainchen commented Mar 1, 2012

any progress?

@igorsantos07

This comment has been minimized.

Show comment
Hide comment
@igorsantos07

igorsantos07 Mar 22, 2012

That would be a really useful feature.
Maybe it can be considered a regression, since "Padrino is based on Sinatra" and Sinatra offers this (in fact, by default).

igorsantos07 commented Mar 22, 2012

That would be a really useful feature.
Maybe it can be considered a regression, since "Padrino is based on Sinatra" and Sinatra offers this (in fact, by default).

@igorsantos07

This comment has been minimized.

Show comment
Hide comment
@igorsantos07

igorsantos07 Apr 9, 2012

Is this issue abandoned?
Maybe I can take a look at it, as it looks fairly simply from my noob point of view.

igorsantos07 commented Apr 9, 2012

Is this issue abandoned?
Maybe I can take a look at it, as it looks fairly simply from my noob point of view.

@DAddYE

This comment has been minimized.

Show comment
Hide comment
@DAddYE

DAddYE Apr 24, 2012

Member

You can use:

uri url(:controller, :action, :param => value)

@nesquena can you improve a guide with this?

Member

DAddYE commented Apr 24, 2012

You can use:

uri url(:controller, :action, :param => value)

@nesquena can you improve a guide with this?

@DAddYE DAddYE closed this Apr 24, 2012

@nesquena

This comment has been minimized.

Show comment
Hide comment
@nesquena

nesquena Apr 24, 2012

Member

Sure, good idea

Member

nesquena commented Apr 24, 2012

Sure, good idea

@igorsantos07

This comment has been minimized.

Show comment
Hide comment
@igorsantos07

igorsantos07 Apr 25, 2012

GOD. Thanks, that solves the problem.
But where is the #uri method? I did a quick search and didn't find it in the API docs...

igorsantos07 commented Apr 25, 2012

GOD. Thanks, that solves the problem.
But where is the #uri method? I did a quick search and didn't find it in the API docs...

@nesquena

This comment has been minimized.

Show comment
Hide comment
Member

nesquena commented Apr 25, 2012

@igorsantos07

This comment has been minimized.

Show comment
Hide comment
@igorsantos07

igorsantos07 Apr 25, 2012

Hmmmm, I got it.
It's a little tricky (at least for me) because the alias #url is recreated
under Padrino, but #uri is not. By the method meaning, they should do the
same...
I still think that absolute urls should be generated by a method like
#abs_url or #url with an option like :absolute => true.

igorsantos07 commented Apr 25, 2012

Hmmmm, I got it.
It's a little tricky (at least for me) because the alias #url is recreated
under Padrino, but #uri is not. By the method meaning, they should do the
same...
I still think that absolute urls should be generated by a method like
#abs_url or #url with an option like :absolute => true.

@rainchen

This comment has been minimized.

Show comment
Hide comment
@rainchen

rainchen Apr 25, 2012

how about using : only_path option, that is a rails style option for url_for :http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-url_for

rainchen commented Apr 25, 2012

how about using : only_path option, that is a rails style option for url_for :http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-url_for

@philipedwards

This comment has been minimized.

Show comment
Hide comment
@philipedwards

philipedwards Aug 12, 2012

What ended up being the outcome of this? I am having trouble finding the appropriate solution in the guides. How does one generate an absolute URL in padrino?

philipedwards commented Aug 12, 2012

What ended up being the outcome of this? I am having trouble finding the appropriate solution in the guides. How does one generate an absolute URL in padrino?

@neezer

This comment has been minimized.

Show comment
Hide comment
@neezer

neezer Dec 31, 2012

Don't know if any additional work has been done with this, but I just coded my own helper method in the meantime:

class MyApp < Padrino::Application
  configure :development do
    set :host, "http://localhost:3112"
  end

  def self.abs_url_for(*args)
    settings.host + url(*args)
  end
end

Use in views like MyApp.abs_url_for(), with same arguments as http://rubydoc.info/github/padrino/padrino-framework/master/Padrino/Routing/ClassMethods#url-instance_method Tried at first with Sinatra's uri mentioned earlier, but as I was trying to get this in a mailer view, was taking me down some rabbit holes as far as requiring libraries that aren't by default, so felt it was easier to just write my own little helper.

My two cents: felt kinda misleading coming over from Rails with this, as I would've expected url_for to give me an absolute url, and to have another method called path_for that gave me a relative path. At the very least, seems like there should be an option for url_for for outputting absolute urls.

neezer commented Dec 31, 2012

Don't know if any additional work has been done with this, but I just coded my own helper method in the meantime:

class MyApp < Padrino::Application
  configure :development do
    set :host, "http://localhost:3112"
  end

  def self.abs_url_for(*args)
    settings.host + url(*args)
  end
end

Use in views like MyApp.abs_url_for(), with same arguments as http://rubydoc.info/github/padrino/padrino-framework/master/Padrino/Routing/ClassMethods#url-instance_method Tried at first with Sinatra's uri mentioned earlier, but as I was trying to get this in a mailer view, was taking me down some rabbit holes as far as requiring libraries that aren't by default, so felt it was easier to just write my own little helper.

My two cents: felt kinda misleading coming over from Rails with this, as I would've expected url_for to give me an absolute url, and to have another method called path_for that gave me a relative path. At the very least, seems like there should be an option for url_for for outputting absolute urls.

@luishurtado

This comment has been minimized.

Show comment
Hide comment
@luishurtado

luishurtado commented Apr 24, 2013

@neezer +1

@dariocravero

This comment has been minimized.

Show comment
Hide comment
@dariocravero

dariocravero Apr 25, 2013

Contributor

Why don't we add that helper and if the setting host is set it defaults to whatever its value is and otherwise it goes and looks for whatever uri can bring back?

Contributor

dariocravero commented Apr 25, 2013

Why don't we add that helper and if the setting host is set it defaults to whatever its value is and otherwise it goes and looks for whatever uri can bring back?

@dariocravero dariocravero reopened this Apr 25, 2013

@dariocravero

This comment has been minimized.

Show comment
Hide comment
@dariocravero
Contributor

dariocravero commented May 16, 2013

@igorsantos07

This comment has been minimized.

Show comment
Hide comment
@igorsantos07

igorsantos07 May 26, 2013

And then, one year later, I'm back in the same issue, trying to create an absolute URL inside a controller's method - to be used with a payment gateway.

Looks like #uri is not available there, although #url is - another sample of visible incompatibility between Sinatra and Padrino API's.

I'm trying to require the needed Sinatra files, but to no avail as well - I think I'm just too rusty with Ruby, after all.

Would there be a better way to do this?

App.controller :cart do |cart|
  def cart.do_stuff
    uri url(:cart, :success)
  end

  post :checkout do
    redirect_to cart.do_stuff
  end
end

igorsantos07 commented May 26, 2013

And then, one year later, I'm back in the same issue, trying to create an absolute URL inside a controller's method - to be used with a payment gateway.

Looks like #uri is not available there, although #url is - another sample of visible incompatibility between Sinatra and Padrino API's.

I'm trying to require the needed Sinatra files, but to no avail as well - I think I'm just too rusty with Ruby, after all.

Would there be a better way to do this?

App.controller :cart do |cart|
  def cart.do_stuff
    uri url(:cart, :success)
  end

  post :checkout do
    redirect_to cart.do_stuff
  end
end

@ghost ghost assigned ujifgc Jul 8, 2013

@ujifgc ujifgc closed this in 2d3554e Jul 8, 2013

dariocravero added a commit that referenced this issue Jul 8, 2013

Merge pull request #1338 from padrino/absolute_url
fix #751, introduce #absolute_url for generating absolute urls

deni64k added a commit to deni64k/padrino-framework that referenced this issue Jul 16, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment