Module: SimpleRest::ActionControllerResponderMethods

Extended by:
ActiveSupport::Concern
Defined in:
lib/simple_rest/action_controller_responder_methods.rb

Instance Method Summary collapse

Instance Method Details

#build_jsonp_message(data, options) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/simple_rest/action_controller_responder_methods.rb', line 49

def build_jsonp_message(data, options)
  message = {:status => options[:status] || 200, :data => data}
  json = message.to_json(options)
  callback, variable = controller.params[:callback], controller.params[:variable]
  if callback && variable
    "var #{variable} = #{json};\n#{callback}(#{variable});"
  elsif variable
    "var #{variable} = #{json};"
  elsif callback
    "#{callback}(#{json});"
  else
    json
  end
end

#simple_to_htmlObject



45
46
47
# File 'lib/simple_rest/action_controller_responder_methods.rb', line 45

def simple_to_html
  render options
end

#simple_to_jsObject



21
22
23
24
# File 'lib/simple_rest/action_controller_responder_methods.rb', line 21

def simple_to_js
  status = options[:status] || :ok
  render :json => resource.to_json(options[:serialize_opts] || {}), :status => status
end

#to_jsonpObject



40
41
42
43
# File 'lib/simple_rest/action_controller_responder_methods.rb', line 40

def to_jsonp
  text = build_jsonp_message(resource, options)
  render ({:content_type => :js, :text => text}.merge(options.merge(:status => :ok)))
end

#to_pdfObject



31
32
33
# File 'lib/simple_rest/action_controller_responder_methods.rb', line 31

def to_pdf
  render (options[:pdf_opts] || {}).merge(:layout => false)
end

#to_xmlObject



35
36
37
38
# File 'lib/simple_rest/action_controller_responder_methods.rb', line 35

def to_xml
  status = options[:status] || :ok
  render :xml => resource.to_xml(options[:serialize_opts] || {}), :status => status
end

#to_yamlObject



26
27
28
29
# File 'lib/simple_rest/action_controller_responder_methods.rb', line 26

def to_yaml
  status = options[:status] || :ok
  render :partial => 'shared/inspect', :content_type => 'text/html', :locals => {:data => resource}, :status => status
end