RackEnv not respected when using route helpers fro

2019-08-29 03:24发布

Running Rails 3.2.13 on Passenger for Apache. My vhost:

<VirtualHost *:80>
ServerName server
DocumentRoot /srv/http
<Directory />
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>

RackEnv test
RackBaseURI /rails_app
<Directory /srv/http/rails_app>
    Options -MultiViews
</Directory>
</VirtualHost>

Works great. Only problem is that I'm using the route url helpers in a model, like so:

# egg.rb
def to_exhibit
  return {
    :edit_path => Rails.application.routes.url_helpers.edit_egg_path(self)
  }
end

When rendering URLs in views, the sub-URI is used as I'd expect it to be, but when accessing the URL helper from within a model, it's discarded and the paths are always relative to the root.

From eggs_controller.rb:

edit_egg_path(1000) --> /rails_app/eggs/1000/edit

From some_model.rb:

edit_egg_path(1000) --> /eggs/1000/edit

Should this work as I expect it to? I don't mind manually fixing this at all, but I'm stumped as to where to find the value of the RackBaseURI so I can insert it manually, if it exists. I'd prefer not to manually define it again in some environment conf since Rails must know about it already.

0条回答
登录 后发表回答