So Rails provides these path helpers, for example, I can, in a view file, have
<%= link_to "edit", edit_admin_article_path(article) %>
This would work both in development environment (localhost) or in production environment. For development, it would generate url
http://localhost:3000/admin/articles/1018/edit
For production, it would generate
http://www.mydomain.com/admin/articles/1018/edit
My question is: how do I force the url to always be the production link even in the development environment? Can I pass a domain value in a hash to the edit_admin_article_path() call?
Thank you.
You probably want the url helper, it will take a domain as an option and make a fqdn.
edit_admin_article_url(article, domain: "production.tld")
It will also pick up any constraints you might have added in the routes.
Edit
For newer version of Rails use
edit_admin_article_url(article, domain: "example.com")
Original answer (Rails 3)
Try
<%= link_to "edit", "http://www.example.com" + edit_admin_article_path(article) %>
You could of course refactor the http://www.example.com
part into a helper method, that way you don't have to keep track of it everywhere if/when you want to change it.
Or you could create an absolute_link_to
method that does what you want by just wrapping the link_to
method.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.