Skip to content

Commit 2ece072

Browse files
committed
Adding a link to the latest version
1 parent 0494699 commit 2ece072

7 files changed

Lines changed: 21 additions & 1 deletion

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
class Api::RelsController < ApplicationController
2+
def show
3+
@rel = Rel.first(:slug => params[:id])
4+
end
25
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
class StaticController < ApplicationController
22
def root; end
33
def api_root; end
4+
def newest_version
5+
render :json => {:version => "1.0.0"}
6+
end
47
end

app/models/rel.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ class Rel
33

44
key :slug, String
55
key :description, String
6+
7+
def to_param
8+
slug
9+
end
610
end

app/views/api/rels/show.html.haml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%h1= "The '#{@rel.slug}' Relation"
2+
3+
%p= @rel.description
4+
5+
%p= link_to "Back to API root", root_path, :rel => "root"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
%h1 Welcome to the Hackety Hack API!
22

3+
%p!= "You can find the latest released version of Hackety Hack " + link_to("here", newest_version_path) + "."
34

config/routes.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
constraints(ApiConstraint) do
44
match '/' => 'static#api_root'
5+
match '/versions/newest' => 'static#newest_version', :as => "newest_version"
56
scope :module => "Api" do
6-
resources :rels
7+
resources :rels, :only => [:show]
78
end
89
end
910

db/seeds.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
#
66
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
77
# Mayor.create(:name => 'Emanuel', :city => cities.first)
8+
9+
Rel.create :slug => "current-application-version",
10+
:description => "The linked resource describes the most recently released version of the desktop application."

0 commit comments

Comments
 (0)