rabl-rails 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.2.1
4
+ * Avoid useless render on POST request with custom responder
5
+ * Custom responder now fallback to Rails default in case the template is not found
6
+
3
7
  ## 0.2.0
4
8
  * Add `root` in DSL to set root without changing the data source
5
9
  * Add XML renderer
@@ -14,20 +14,33 @@ module RablRails
14
14
  end
15
15
  end
16
16
 
17
+ def to_format
18
+ if get? || response_overridden?
19
+ default_render
20
+ elsif has_errors?
21
+ display_errors
22
+ else
23
+ api_behavior(nil)
24
+ end
25
+ end
26
+
17
27
  protected
18
28
 
19
29
  def api_behavior(error)
20
- template = @controller.respond_to?(:responder_default_template, true) ? controller.send(:responder_default_template)
21
- : RablRails.responder_default_template
22
- rabl_options = options.merge(template: template)
30
+ if post?
31
+ template = if @controller.respond_to?(:responder_default_template, true)
32
+ controller.send(:responder_default_template)
33
+ else
34
+ RablRails.responder_default_template
35
+ end
36
+ options[:template] ||= "#{@controller.controller_name}/#{template}"
23
37
 
24
- if get?
25
- controller.default_render rabl_options
26
- elsif post?
27
- controller.default_render rabl_options.merge!(status: :created, location: api_location)
38
+ controller.default_render options.merge(status: :created, location: api_location)
28
39
  else
29
40
  head :no_content
30
41
  end
42
+ rescue ActionView::MissingTemplate => e
43
+ super(e)
31
44
  end
32
45
  end
33
46
  end
@@ -1,3 +1,3 @@
1
1
  module RablRails
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabl-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-24 00:00:00.000000000 Z
12
+ date: 2012-09-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport