我正在使用虚荣宝石进行电子邮件 ab 测试
为了跟踪点击次数,我使用虚荣教程:
<%= link_to "see my page HERE", vanity_track_url_for(Vanity.context.vanity_identity, :metric, :controller => "controller" :action => "method", host => "myhost.com") %>
但我也使用 URL 缩短器为我提供易腐烂的链接 (expires_at)
我的 Rails 路线包含:
get '/s/:id' => "shortened_urls#show"
我加入其中:
resources :shortened_urls
所以当我使用时,虚荣 url_for 正在工作:
<%= link_to "see my page HERE too", vanity_track_url_for(Vanity.context.vanity_identity, :metric, :controller => "shortened_urls", :action => "show", :host => "myhost.com", :id => @short.unique_key) %>
但网址看起来像myhost.com/shortened_urls/aX5DtE5z69A 我想要myhost.com/s/aX5DtE5z69A
我知道如何在 apache 主机中重写 url:
RewriteRule ^/shortened_urls/(.*)$ /s/$1 [R=301,NC,L]
但我想知道rails中是否有捷径可以做到:)