Tuesday, September 25, 2007

helper: Getting the full URL

There’s nothing built in Rails that gives you the full URL. I made a helper, that gives this to you. It doesn’t display properly here.


def get_full_url(base_url)
return base_url + request.path + get_params_as_url_friendly
end

def get_params_as_url_friendly
count = 0
param_size = request.query_parameters.size
parameters = ""

for param in request.query_parameters
parameter = "#{param[0]}=#{param[1]}"

if count == 0
parameter = "?#{parameter}"
else
parameter = "&#{parameter}"
end

count += 1
parameters += parameter
end

return parameters
end

2 comments:

Anonymous said...

you suck

Anonymous said...

What a dumb comment. Thanks a lot for contributing your article.