Class: DescribedRoutes::RailsController

Inherits:
ActionController::Base
  • Object
show all
Includes:
DescribedRoutesHelper
Defined in:
lib/described_routes/rails_controller.rb

Constant Summary

Constants included from DescribedRoutesHelper

DescribedRoutesHelper::LINK_ELEMENT_OPTIONS, DescribedRoutesHelper::LINK_HEADER_OPTIONS, DescribedRoutesHelper::REGISTERED_RELS

Instance Method Summary collapse

Methods included from DescribedRoutesHelper

#link_elements, #make_link_header, #resource_parameters, #resource_template, #resource_templates

Instance Method Details

#indexObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/described_routes/rails_controller.rb', line 11

def index
  expanded_templates = resource_templates.partial_expand(request.query_parameters)
  
  respond_to do |format|
    format.html { render rescue redirect_to :format => :text } # render index.html.erb or fall back to text
    format.json { render :json => expanded_templates.to_json }
    format.text { render :text => expanded_templates.to_text }
    format.yaml { render :text => expanded_templates.to_yaml }
    format.xml  { render :xml  => expanded_templates.to_xml(Builder::XmlMarkup.new(:indent => 2)).target! }
  end
end


38
39
40
41
# File 'lib/described_routes/rails_controller.rb', line 38

def set_link_header
  rel = request.path == described_routes_path ? "self" : "index"
  response.headers["Link"] = %Q(<#{described_routes_url}>; rel="#{rel}"; meta="ResourceTemplates")
end

#showObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/described_routes/rails_controller.rb', line 23

def show
  expanded_templates = resource_templates.partial_expand(request.query_parameters)
  resource_template = resource_templates.all_by_name[params[:id]]
  # TODO 404 if nil
  resource_template = resource_template.partial_expand(request.query_parameters)
  
  respond_to do |format|
    format.html { render rescue redirect_to :format => :text } # render show.html.erb or fall back to text
    format.json { render :json => resource_template.to_json }
    format.text { render :text => resource_template.to_text }
    format.yaml { render :text => resource_template.to_yaml }
    format.xml  { render :xml  => resource_template.to_xml(Builder::XmlMarkup.new(:indent => 2)).target! }
  end
end