In order to be able to see if a User has shared my page on Facebook, I want to be able to create this kind of URLs:
http://graph.facebook.com/?id=http://stylehatch.co/some_unique_user_token
Where http://stylehatch.co would need to be my base URL. I am thinking on having a method in the User model that will build and return that URL, but I can't access root_url from within my model.
How can I get the base URL of my application from a Model?
Say if my urls look like this:
http://myapp.com/users/new
http://myapp.com/users/2/show
How can I get the "http://myapp.com" from my model? I have added:
include Rails.application.routes.url_helpers
in my model, but it seems that root_url is nil. Any thoughts? Is this correct to be a Model method, or should I place it in a helper?
Thanks
You may use environment variables:
ROOT_URL=http://myapp.com
ENV['ROOT_URL']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With