-
Notifications
You must be signed in to change notification settings - Fork 5
How it works
johnadamsDFID edited this page Jul 20, 2015
·
1 revision
This file controls the application routing. The file has the following parts:
This loads both the gems needed and any helper functions
# devtracker.rb
#require 'rubygems'
#require 'bundler'
#Bundler.setup
require 'sinatra'
require 'json'
require 'rest-client'
#helpers
require_relative 'helpers/formatters.rb'
require_relative 'helpers/oipa_helpers.rb'
require_relative 'helpers/codelists.rb'
require_relative 'helpers/lookups.rb'
require_relative 'helpers/project_helpers.rb'
#ensures that we can use the extension html.erb rather than just .erb
Tilt.register Tilt::ERBTemplate, 'html.erb'
This is where routing is static. The code captures the route (the /? indicates that the trailing slash is optional so that it will work with both about
and `about/. The only parameter passed is the pointer to the layout file.
get '/about/?' do
erb :'about/index', :layout => :'layouts/layout'
end
This routes to the dynamic pages where we are using the OIPA API. This captures the routing request, calls the OIPA API and then passes the resulting project result set to the page.
#Project test page
get '/projects/:proj_id/test/?' do |n|
# get the project data from the API
oipa = RestClient.get "http://149.210.176.175/api/activities/#{n}?format=json"
project = JSON.parse(oipa)
erb :'projects/test',
:layout => :'layouts/layout',
:locals => {
project: project
}
end