[38264] branches/gsoc08-mpwa/app
digx at macports.org
digx at macports.org
Sun Jul 13 23:25:57 PDT 2008
Revision: 38264
http://trac.macosforge.org/projects/macports/changeset/38264
Author: digx at macports.org
Date: 2008-07-13 23:25:57 -0700 (Sun, 13 Jul 2008)
Log Message:
-----------
Cleaned up tags a bit
Modified Paths:
--------------
branches/gsoc08-mpwa/app/controllers/tags_controller.rb
branches/gsoc08-mpwa/app/models/tag.rb
Modified: branches/gsoc08-mpwa/app/controllers/tags_controller.rb
===================================================================
--- branches/gsoc08-mpwa/app/controllers/tags_controller.rb 2008-07-14 06:25:40 UTC (rev 38263)
+++ branches/gsoc08-mpwa/app/controllers/tags_controller.rb 2008-07-14 06:25:57 UTC (rev 38264)
@@ -1,19 +1,11 @@
class TagsController < ApplicationController
def index
- @tags = Tag.paginate :all, :per_page => 128, :page => params[:page]
+ @tags = Tag.paginate(:all, :per_page => 128, :page => params[:page])
end
- def show
- if !params[:name].nil?
- @key = params[:name]
- @tag = Tag.find_by_name(params[:name])
- render :action => 'notag' if @tag.nil?
- else
- @key = params[:id]
- @tag = Tag.find(params[:id])
- render :action => 'notag' if @tag.nil?
- end
+ def show
+ @tag = Tag.find_by_name_or_id(params[:id])
end
def new
Modified: branches/gsoc08-mpwa/app/models/tag.rb
===================================================================
--- branches/gsoc08-mpwa/app/models/tag.rb 2008-07-14 06:25:40 UTC (rev 38263)
+++ branches/gsoc08-mpwa/app/models/tag.rb 2008-07-14 06:25:57 UTC (rev 38264)
@@ -1,11 +1,18 @@
-require 'port'
-require 'port_pkg'
-
class Tag < ActiveRecord::Base
- has_and_belongs_to_many :ports
- has_and_belongs_to_many :port_pkgs
+ has_and_belongs_to_many :ports
+ has_and_belongs_to_many :port_pkgs
- def <=>(other)
- self.name <=> other.name
+ before_save 'self.name = name.downcase' # force tag name to be lowercase
+
+ def <=>(other)
+ self.name <=> other.name
+ end
+
+ def self.find_by_name_or_id(id, *args)
+ if tag = (find_by_name(id, *args) || find_by_id(id, *args))
+ return tag
+ else
+ raise ActiveRecord::RecordNotFound, "Couldn't find #{self.name} with ID=#{id}"
end
-end
+ end
+end
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20080713/00c3f320/attachment.html
More information about the macports-changes
mailing list