Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
Better way to find latest version by name
Browse files Browse the repository at this point in the history
  • Loading branch information
sj26 committed Aug 1, 2012
1 parent 1a4c7a5 commit c5bd388
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/versions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def search?
def prepare_version
@version = Version.find_by_full_name! params[:id]
rescue ActiveRecord::RecordNotFound
if @version = Version.ordered.not_prerelease.find_by_name(params[:id])
if @version = Version.find_using_name(params[:id])
redirect_to @version
else
redirect_to versions_path(search: params[:id])
Expand Down
5 changes: 5 additions & 0 deletions app/models/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ def self.ordered
order("name ASC", "version_order ASC", "created_at DESC")
end

def self.find_using_name name
where(name: name).not_prerelease.ordered.first or
where(name: name).ordered.first
end

def full_name
"#{name}-#{version}#{"-#{platform}" unless platform.nil? or platform == "ruby"}"
end
Expand Down

0 comments on commit c5bd388

Please sign in to comment.