How to create a url for notification in Rails
i want to send an email to user after he sign-up with code.for ex
http://192.168.1.51:3000/l开发者_如何学Pythonogins/activate/435546dgfd757676657 #link contains in an email
how can i create the above URL in my notifier model. i know following way
url_for :controller=>'logins', :action=>'activate', :id=>'435546dgfd757676657' , :host=>'http://192.168.1.54:3000'
Which is working properly. what i want that host should not be hard coded. How can i get host with port in a model.
In controller i can find it using follwing ways
request.host_with_port
Please provide me correct ruby way for doing same.
You can define the host in your environment.rb file.
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
As your host probably changes depending of your environment (development, test, production), it's better to put that config line inside the environment file.
After that, every link in emails will be made with that host. You don't have to provide it in the view anymore.
精彩评论