views:

26

answers:

1

Hello all, I'm working with a rails app which plays mp3s. Is there a way to catch the request for the mp3 file with ruby, reformat the request(url), and pass the request along?

I'm really just trying to protect the urls...

+1  A: 

I'm not sure I exactly understand what you want to do, but wouldn't just catching the path in your Routes file and passing it to an action (or doing it directly in the Routes file in Rails 3) which will redirect_to the path you want?

Take 2

So to encrypt you might want to do something like this: In song.rb (the model):

class Song < ActiveRecord::Base

  before_create :create_secret_param

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

end

This will create a secret param that you can use to access it.

In routes.rb

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

In 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

This should point you in the right direction, though you will have to get the details right for your app.

Jakub Hampl
I've got a flash player on the site. I want to catch the request it makes for song files (say, from amazon), reformat the url of the file being requested, and the allow the request to continue with a reformatted url
danwoods
I think you way might be what I'm looking for, can you explain it in any more detail? I'm really just trying to encrypt the file urls
danwoods
Hope Take 2 helps you out.
Jakub Hampl
It gives me a lot to go on. Thanks
danwoods