2010-05-10 26 views

回答

1

我不知道我究竟明白你想做的事,但不會只是抓住你的路由文件的路徑和傳遞到一個動作(或者直接在Rails 3中的Routes文件中執行),這將是你想要的路徑redirect_to

取2

所以加密你可能想要做這樣的事情: 在song.rb(模型):

class Song < ActiveRecord::Base 

    before_create :create_secret_param 

    private 
    def create_secret_param 
    self.secret = rand(100000) 
    end 

end 

這將創建一個祕密PARAM,你可以用它來訪問它。

routes.rb

map.secret_song ':id:secret', :controller => 'songs', :action => 'show', :id => /\d+/, :secret => /\d{5}/ 

song_controller.rb

def show 
    if param[:secret] 
    @song = Song.find param[:id], :conditions => {:secret => params[:secret]} 
    elsif # check if is user is ok or whatever 
    @song = Song.find param[:id] 
    redirect_to secret_song_url(:id => @song.id, :secret => @song.secret) 
    end 
end 

這應該指向你在正確的方向,但你必須瞭解詳細內容適合您的應用程序。

+0

我在網站上有一個Flash播放器。我想要捕捉它爲歌曲文件(例如,來自亞馬遜)製作的請求,重新格式化所請求的文件的URL,並允許請求繼續使用重新格式化的URL – danwoods 2010-05-10 00:52:53

+0

我想你的方式可能是我正在尋找的東西因爲,你能否更詳細地解釋它?我真的只是想加密文件的URL – danwoods 2010-05-10 00:53:47

+0

希望拿2幫助你。 – 2010-05-10 02:15:04