Skip to content

Commit a4ff44c

Browse files
committed
Adding rel index
1 parent ee1a61c commit a4ff44c

6 files changed

Lines changed: 25 additions & 9 deletions

File tree

app/controllers/api/rels_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
class Api::RelsController < ApplicationController
2+
def index
3+
@rels = Rel.all
4+
end
5+
26
def show
37
@rel = Rel.first(:slug => params[:id])
48
end

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
%h1 All rels
2+
3+
%p Here's a list of all of the relations the API supports:
4+
5+
%ul
6+
- @rels.each do |rel|
7+
%li= link_to rel.slug, rel
8+
9+
%p= link_to "Back to API root", root_path, :rel => "root"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
%p= @rel.description
44

5+
%p= link_to "Back to list of all rels", rels_path, :rel => "/rels/rel-index"
56
%p= link_to "Back to API root", root_path, :rel => "root"
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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) + "."
3+
%p!= "For a list of the relations we've defined for this API, go " + link_to("here", rels_path, :rel => "/rels/rel-index")
4+
%p!= "You can find the latest released version of Hackety Hack " + link_to("here", newest_version_path, :rel => "/rels/current-application-version") + "."
45

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
match '/' => 'static#api_root'
55
match '/versions/newest' => 'static#newest_version', :as => "newest_version"
66
scope :module => "Api" do
7-
resources :rels, :only => [:show]
7+
resources :rels, :only => [:index, :show]
88
end
99
end
1010

db/seeds.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
# This file should contain all the record creation needed to seed the database with its default values.
2-
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3-
#
4-
# Examples:
5-
#
6-
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
7-
# Mayor.create(:name => 'Emanuel', :city => cities.first)
1+
# Drop all the old Rels
82

3+
Rel.all.each{|r| r.destroy}
4+
5+
#Make our standard ones
96
Rel.create :slug => "current-application-version",
107
:description => "The linked resource describes the most recently released version of the desktop application."
8+
Rel.create :slug => "rel-index",
9+
:description => "This relation is the root resource for rels. It contains the list of all rels we've defined."
10+
Rel.create :slug => "rel",
11+
:description => "This relation is a link to a rel resource."

0 commit comments

Comments
 (0)