我正在使用vanity gem进行电子邮件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)
我的路轨路线包含:
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
我知道如何使用apach主机中的URL重写来实现它:
RewriteRule ^/shortened_urls/(.*)$ /s/$1 [R=301,NC,L]
但是我想知道是否在Rails中有一个捷径可以做到:)