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

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

url helper to generate absolute URL #751

pke opened this issue Jan 10, 2012 · 17 comments

Comments

@pke
Copy link

pke commented Jan 10, 2012

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

@joshbuddy
Copy link
Contributor

yeah, I'm working on this now.

@pke
Copy link
Author

pke commented Jan 10, 2012

Great, thanks!

@ghost ghost assigned joshbuddy Jan 11, 2012
@rainchen
Copy link

rainchen commented Mar 1, 2012

any progress?

@igorsantos07
Copy link

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
Copy link

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

@DAddYE
Copy link
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 as completed Apr 24, 2012
@nesquena
Copy link
Member

Sure, good idea

@igorsantos07
Copy link

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
Copy link
Member

@igorsantos07
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

@neezer +1

@dariocravero
Copy link

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
Copy link

@padrino/core-members thoughts?

@igorsantos07
Copy link

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 as completed in 2d3554e Jul 8, 2013
dariocravero pushed a commit that referenced this issue Jul 8, 2013
fix #751, introduce #absolute_url for generating absolute urls
deni64k pushed 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
Projects
None yet
Development

No branches or pull requests