tl;dnr:我的页面链接很好,但链接到非页面文本(电子邮件)缺少生产应用程序安装点。
detail:我的 RoR 应用程序在开发和生产中使用略有不同的 URL:在开发中,顶级实体是资源模型:
http://localhost:3000/ENTITY/1/edit
但在生产中,应用程序安装在下一级,因此 URLS 有一个额外的术语:
https://server.example.com/APP/ENTITY/1/edit
这对于大多数情况都适用: url_helpers 就像edit_entity_url
返回我所显示的 URL。坦率地说,我不太清楚这是如何运作的;我想 Phusion Passenger 和 Rack 可以解决这个问题吗?
但是,当我发送电子邮件(例如确认密码重置)时,它不起作用:edit_entity_url
从不添加APP
挂载点。 ERB 中缺少我自己的条件逻辑,我怎样才能在那里得到“/APP”?
我尝试过的事情:
- 设置 `Rails.application.routes.default_url_options[:host] 以包含“/registry”(无效)
- using
<%= link_to 'Reset', edit_entity_url(...) %>
(没有帮助)
版本信息:
- 动作邮件程序 (4.0.2)
- 导轨 4.0.2
- 红宝石2.1.0p0
- 机架 (1.5.2)
- 乘客 (4.0.35)
Apache“启用站点”文件将事物联系在一起(也是我能找到定义“/registry”令牌的唯一位置):
<VirtualHost *:80>
ServerName server.example.com
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
Alias /registry /app01/capapp/registry/current/public
<Location /registry>
PassengerBaseURI /registry
PassengerAppRoot /app01/capapp/registry/current
</Location>
<Directory /app01/capapp/registry/current/public>
Allow from all
Options -MultiViews
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
铁轨config/environments/production.rb
file.
Registration::Application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.assets.version = '1.0'
config.log_level = :debug
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
Rails.application.routes.default_url_options[:host] = "server.example.com"
end
Registration::Application.config.middleware.use ExceptionNotification::Rack,
:email => {
:email_prefix => "[Registration]",
:sender_address => %{"Admin" <[email protected] /cdn-cgi/l/email-protection>},
:exception_recipients => %w{[email protected] /cdn-cgi/l/email-protection}
}
查看电子邮件(app/views/user_mailer/password_reset.text.erb
):
To reset your password click the URL below.
<%= edit_password_reset_url(@user.password_reset_token) %>
If you did not request your password to be reset please ignore this email
and your password will stay as it is.
是的,将 URL 基于 reset_token 而不是 user_id 很奇怪,但它是在控制器中处理的。结构基于轨道广播#274 http://asciicasts.com/episodes/274-remember-me-reset-password