Changeset 38264


Ignore:
Timestamp:
Jul 14, 2008, 6:25:57 AM (11 years ago)
Author:
digx@…
Message:

Cleaned up tags a bit

Location:
branches/gsoc08-mpwa/app
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/gsoc08-mpwa/app/controllers/tags_controller.rb

    r38165 r38264  
    22   
    33  def index
    4     @tags = Tag.paginate :all, :per_page => 128, :page => params[:page]
     4    @tags = Tag.paginate(:all, :per_page => 128, :page => params[:page])
    55  end
    66
    7   def show
    8     if !params[:name].nil?
    9         @key = params[:name]
    10         @tag = Tag.find_by_name(params[:name])
    11         render :action => 'notag' if @tag.nil?
    12     else
    13         @key = params[:id]
    14         @tag = Tag.find(params[:id])
    15         render :action => 'notag' if @tag.nil?
    16     end
     7  def show   
     8    @tag = Tag.find_by_name_or_id(params[:id])
    179  end
    1810
  • branches/gsoc08-mpwa/app/models/tag.rb

    r38165 r38264  
    1 require 'port'
    2 require 'port_pkg'
     1class Tag < ActiveRecord::Base
     2  has_and_belongs_to_many :ports
     3  has_and_belongs_to_many :port_pkgs
    34
    4 class Tag < ActiveRecord::Base
    5     has_and_belongs_to_many :ports
    6     has_and_belongs_to_many :port_pkgs
     5  before_save 'self.name = name.downcase' # force tag name to be lowercase
    76
    8     def <=>(other)
    9         self.name <=> other.name
     7  def <=>(other)
     8      self.name <=> other.name
     9  end
     10 
     11  def self.find_by_name_or_id(id, *args)
     12    if tag = (find_by_name(id, *args) || find_by_id(id, *args))
     13      return tag
     14    else
     15      raise ActiveRecord::RecordNotFound, "Couldn't find #{self.name} with ID=#{id}"
    1016    end
     17  end
    1118end
Note: See TracChangeset for help on using the changeset viewer.