GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Pretty url support for Ruby on Rails applications
Homepage: http://www.caring.com
Clone URL: git://github.com/caring/acts_as_url_param.git
Chris Eppstein (author)
Tue Mar 25 07:48:23 -0700 2008
commit  d6c53692da2d7aaa70cad14ea23f8e5d5f96ded3
tree    ebd2b427b439bc423b75081f4ee3885906c8b4cb
parent  9c1d2a5bdebfae3a49a7727f126be58a7f585992
acts_as_url_param / lib / redirect.rb
100644 23 lines (18 sloc) 0.498 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# redirectable_type
# redirectable_id
# redirectable_class
# name
 
class Redirect < ActiveRecord::Base
  belongs_to :redirectable, :polymorphic => true
  before_create :set_real_class
  
  def self.find_by_class_and_name(klass,name)
    find(:first, :conditions => ["redirectable_class = ? AND url_name = ?", klass.to_s, name], :order => "created_at desc")
  end
  
  def to_label
    url_name
  end
  
  private
  def set_real_class
    self.redirectable_class = redirectable.class.to_s
  end
end