Rails: explicitly tell rails the port it's running on
I've got the following problem. I want to explicitly tell rails the port it is running on, so that the _url helper will use that port instead开发者_开发问答 of the autodiscovered port.
The underlying problem is, that I have thin serving my rails app and apache serving static content. This works fine as long as the website is accessed on port 80 (apache) but not when accessed on the port thin is running on. (Which is the port that get's auto discovered.)
Rails is supposed to create relative links, which do not include the fully qualified domain name, see example here, I quote :
link_to "Profile", profile_path(@profile)
# => <a href="/profiles/1">Profile</a>;
the *_url shortcuts, on the other hand, are using the full path, which is bad when you're behind a reverse proxy (that's apache in your case).
Have you tried using only *_path for links, and *_url for redirects, as, in the case of a redirect, apache should rewrite the url to match its port (assuming you're using the ProxyPass and ProxyPassReverse directives at Apache level) ?
If you use url_for, you can force it to be relative by setting the :only_path to true.
If your apache configuration is not based on ProxyPass, could you please copy/paste the interesting part so I can fix this answer ?
Thanks in advance.
Because Ruby on Rails uses its own server, users visiting your website (and subsequently your Ruby on Rails application) will need to be redirected to the appropriate port.
To change the port of Ruby on Rails server you should start the server with the -p option:
ruby s -p <port-number>
精彩评论