jbuilder 2.7.0 → 2.10.2
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.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/.travis.yml +34 -48
- data/Appraisals +16 -12
- data/CHANGELOG.md +44 -0
- data/CONTRIBUTING.md +0 -2
- data/Gemfile +0 -1
- data/MIT-LICENSE +1 -1
- data/README.md +32 -16
- data/gemfiles/rails_5_0.gemfile +1 -4
- data/gemfiles/rails_5_1.gemfile +1 -4
- data/gemfiles/{rails_4_2.gemfile → rails_5_2.gemfile} +1 -4
- data/gemfiles/rails_6_0.gemfile +10 -0
- data/gemfiles/rails_head.gemfile +10 -0
- data/jbuilder.gemspec +9 -4
- data/lib/generators/rails/jbuilder_generator.rb +8 -2
- data/lib/generators/rails/scaffold_controller_generator.rb +6 -0
- data/lib/generators/rails/templates/api_controller.rb +4 -4
- data/lib/generators/rails/templates/controller.rb +9 -9
- data/lib/generators/rails/templates/index.json.jbuilder +1 -1
- data/lib/generators/rails/templates/partial.json.jbuilder +1 -1
- data/lib/jbuilder/jbuilder_template.rb +10 -9
- data/lib/jbuilder.rb +13 -12
- data/test/jbuilder_dependency_tracker_test.rb +1 -1
- data/test/jbuilder_generator_test.rb +13 -5
- data/test/jbuilder_template_test.rb +193 -338
- data/test/jbuilder_test.rb +31 -3
- data/test/scaffold_api_controller_generator_test.rb +6 -2
- data/test/scaffold_controller_generator_test.rb +11 -7
- data/test/test_helper.rb +26 -6
- metadata +9 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 977b17be8a840c956c4043e24671792174502c57de951e215873b80b66b1031d
|
4
|
+
data.tar.gz: 847725cdbcfca6ba030942fa9d63b35b0fffd729587774c2dd020eaf75b0b786
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcf001b86052df2bf45e8040630a6c3bcb9cb5ee5fee7910a636706fc7c05350a3a86feab542541f5b8290435fd8be61c8ca9cc17c1b1a3b87fb6626aeb9b495
|
7
|
+
data.tar.gz: 44d59c94049d3f76c9b3111408aabe16631deb5ef80fbde72a6e43a2a5807c2da3e47725dc8974384212cba178a48b76bb61cd114433593ccfd0dc3311e92b07
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,66 +1,52 @@
|
|
1
1
|
language: ruby
|
2
2
|
|
3
|
-
sudo: false
|
4
3
|
cache: bundler
|
5
4
|
|
5
|
+
before_install:
|
6
|
+
- "gem install bundler -v '<2'"
|
7
|
+
|
6
8
|
rvm:
|
7
|
-
-
|
8
|
-
- 2.
|
9
|
-
- 2.
|
10
|
-
- 2.
|
11
|
-
- 2.
|
12
|
-
- 2.
|
9
|
+
- 2.2.10
|
10
|
+
- 2.3.8
|
11
|
+
- 2.4.10
|
12
|
+
- 2.5.8
|
13
|
+
- 2.6.6
|
14
|
+
- 2.7.1
|
13
15
|
- ruby-head
|
14
|
-
- jruby-19mode
|
15
|
-
- rbx
|
16
16
|
|
17
17
|
gemfile:
|
18
|
-
- gemfiles/rails_3_0.gemfile
|
19
|
-
- gemfiles/rails_3_1.gemfile
|
20
|
-
- gemfiles/rails_3_2.gemfile
|
21
|
-
- gemfiles/rails_4_0.gemfile
|
22
|
-
- gemfiles/rails_4_1.gemfile
|
23
|
-
- gemfiles/rails_4_2.gemfile
|
24
18
|
- gemfiles/rails_5_0.gemfile
|
25
19
|
- gemfiles/rails_5_1.gemfile
|
20
|
+
- gemfiles/rails_5_2.gemfile
|
21
|
+
- gemfiles/rails_6_0.gemfile
|
22
|
+
- gemfiles/rails_head.gemfile
|
26
23
|
|
27
24
|
matrix:
|
28
|
-
allow_failures:
|
29
|
-
- rvm: jruby-19mode
|
30
|
-
- rvm: rbx
|
31
|
-
- rvm: ruby-head
|
32
|
-
fast_finish: true
|
33
25
|
exclude:
|
34
|
-
- rvm: 1
|
35
|
-
gemfile: gemfiles/rails_5_0.gemfile
|
36
|
-
- rvm: 1.9
|
37
|
-
gemfile: gemfiles/rails_5_1.gemfile
|
38
|
-
- rvm: 2.0
|
39
|
-
gemfile: gemfiles/rails_5_0.gemfile
|
40
|
-
- rvm: 2.0
|
41
|
-
gemfile: gemfiles/rails_5_1.gemfile
|
42
|
-
- rvm: 2.1
|
26
|
+
- rvm: 2.7.1
|
43
27
|
gemfile: gemfiles/rails_5_0.gemfile
|
44
|
-
- rvm: 2.1
|
28
|
+
- rvm: 2.7.1
|
45
29
|
gemfile: gemfiles/rails_5_1.gemfile
|
46
|
-
- rvm:
|
47
|
-
gemfile: gemfiles/
|
48
|
-
- rvm:
|
49
|
-
gemfile: gemfiles/
|
50
|
-
- rvm:
|
51
|
-
gemfile: gemfiles/
|
52
|
-
- rvm:
|
53
|
-
gemfile: gemfiles/
|
54
|
-
- rvm: 2.4.
|
55
|
-
gemfile: gemfiles/
|
56
|
-
- rvm: 2.
|
57
|
-
gemfile: gemfiles/
|
58
|
-
- rvm: 2.
|
59
|
-
gemfile: gemfiles/
|
60
|
-
- rvm: 2.4.
|
61
|
-
gemfile: gemfiles/
|
62
|
-
|
63
|
-
|
30
|
+
- rvm: 2.2.10
|
31
|
+
gemfile: gemfiles/rails_5_2.gemfile
|
32
|
+
- rvm: 2.7.1
|
33
|
+
gemfile: gemfiles/rails_5_2.gemfile
|
34
|
+
- rvm: 2.2.10
|
35
|
+
gemfile: gemfiles/rails_6_0.gemfile
|
36
|
+
- rvm: 2.3.8
|
37
|
+
gemfile: gemfiles/rails_6_0.gemfile
|
38
|
+
- rvm: 2.4.10
|
39
|
+
gemfile: gemfiles/rails_6_0.gemfile
|
40
|
+
- rvm: 2.2.10
|
41
|
+
gemfile: gemfiles/rails_head.gemfile
|
42
|
+
- rvm: 2.3.8
|
43
|
+
gemfile: gemfiles/rails_head.gemfile
|
44
|
+
- rvm: 2.4.10
|
45
|
+
gemfile: gemfiles/rails_head.gemfile
|
46
|
+
allow_failures:
|
47
|
+
- rvm: ruby-head
|
48
|
+
- gemfile: gemfiles/rails_head.gemfile
|
49
|
+
fast_finish: true
|
64
50
|
|
65
51
|
notifications:
|
66
52
|
email: false
|
data/Appraisals
CHANGED
@@ -1,17 +1,21 @@
|
|
1
|
-
appraise "rails-4-2" do
|
2
|
-
gem "railties", "~> 4.2.0"
|
3
|
-
gem "actionpack", "~> 4.2.0"
|
4
|
-
gem "activemodel", "~> 4.2.0"
|
5
|
-
end
|
6
|
-
|
7
1
|
appraise "rails-5-0" do
|
8
|
-
gem "
|
9
|
-
gem "actionpack", "~> 5.0.0"
|
10
|
-
gem "activemodel", "~> 5.0.0"
|
2
|
+
gem "rails", "~> 5.0.0"
|
11
3
|
end
|
12
4
|
|
13
5
|
appraise "rails-5-1" do
|
14
|
-
gem "
|
15
|
-
|
16
|
-
|
6
|
+
gem "rails", "~> 5.1.0"
|
7
|
+
end
|
8
|
+
|
9
|
+
appraise "rails-5-2" do
|
10
|
+
gem "rails", "~> 5.2.0"
|
11
|
+
end
|
12
|
+
|
13
|
+
if RUBY_VERSION >= "2.5.0"
|
14
|
+
appraise "rails-6-0" do
|
15
|
+
gem "rails", "~> 6.0.0"
|
16
|
+
end
|
17
|
+
|
18
|
+
appraise "rails-head" do
|
19
|
+
gem "rails", github: "rails/rails"
|
20
|
+
end
|
17
21
|
end
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,49 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
2.10.2
|
4
|
+
----------
|
5
|
+
|
6
|
+
* Update scaffold generator to use double quotes, 422 form error responds, and modern string-of-arrays syntax [DHH]
|
7
|
+
|
8
|
+
2.10.1
|
9
|
+
----------
|
10
|
+
|
11
|
+
* Fix keyword arguments warning on Ruby 2.7
|
12
|
+
|
13
|
+
2.10.0
|
14
|
+
----------
|
15
|
+
|
16
|
+
* Requires Rails 5+ and Ruby 2.2+
|
17
|
+
* Nested hashes are deep-merged
|
18
|
+
|
19
|
+
2.9.1
|
20
|
+
-----
|
21
|
+
|
22
|
+
* [Respect JSON encoding customizations](https://github.com/rails/jbuilder/commit/e2e8623b08078ad6a2323ce8ecaf642b7afe1166)
|
23
|
+
|
24
|
+
2.9.0
|
25
|
+
-----
|
26
|
+
|
27
|
+
* [Fix passing object with partial without locals](https://github.com/rails/jbuilder/pull/435)
|
28
|
+
* [Fix deprecation warning in Rails 6.0](https://github.com/rails/jbuilder/pull/453)
|
29
|
+
* [Use quotes consistently in generated templates](https://github.com/rails/jbuilder/pull/455)
|
30
|
+
* [Allow omitting timestamps from generated partials](https://github.com/rails/jbuilder/pull/448)
|
31
|
+
* [Respect changing scaffold generator](https://github.com/rails/jbuilder/pull/458)
|
32
|
+
* [Use a symbolic default format for Rails 6.0 forward compatibility](https://github.com/rails/jbuilder/commit/3895a7243f3db292b0bf15513fc05494e6e50576)
|
33
|
+
* [Drop MultiJSON in favor of Ruby standard library JSON](https://github.com/rails/jbuilder/commit/b952ae096eb1828b0fcfde06e6ba62311494ec49)
|
34
|
+
|
35
|
+
2.8.0
|
36
|
+
-----
|
37
|
+
|
38
|
+
* [Replace deprecated fragment_cache_key for Rails 5.2 support](https://github.com/rails/jbuilder/pull/430)
|
39
|
+
|
40
|
+
2.7.0
|
41
|
+
-----
|
42
|
+
|
43
|
+
* [Requires Rails 4+](https://github.com/rails/jbuilder/commit/5207ff394533177fffdd768bfaa6413a0cd16dc8)
|
44
|
+
* [Fix implicitly rendering a JSON partial with the same name as an
|
45
|
+
HTML partial](https://github.com/rails/jbuilder/pull/400)
|
46
|
+
|
3
47
|
2.6.4
|
4
48
|
-----
|
5
49
|
|
data/CONTRIBUTING.md
CHANGED
@@ -4,12 +4,10 @@ Contributing to Jbuilder
|
|
4
4
|
[][travis]
|
5
5
|
[][gem]
|
6
6
|
[][codeclimate]
|
7
|
-
[][gemnasium]
|
8
7
|
|
9
8
|
[travis]: https://travis-ci.org/rails/jbuilder
|
10
9
|
[gem]: https://rubygems.org/gems/jbuilder
|
11
10
|
[codeclimate]: https://codeclimate.com/github/rails/jbuilder
|
12
|
-
[gemnasium]: https://gemnasium.com/rails/jbuilder
|
13
11
|
|
14
12
|
Jbuilder is work of [many contributors](https://github.com/rails/jbuilder/graphs/contributors). You're encouraged to submit [pull requests](https://github.com/rails/jbuilder/pulls), [propose features and discuss issues](https://github.com/rails/jbuilder/issues).
|
15
13
|
|
data/Gemfile
CHANGED
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -67,6 +67,19 @@ end
|
|
67
67
|
# => {"author": { "name": "David" }}
|
68
68
|
```
|
69
69
|
|
70
|
+
|
71
|
+
To merge existing hash or array to current context:
|
72
|
+
|
73
|
+
``` ruby
|
74
|
+
hash = { author: { name: "David" } }
|
75
|
+
json.post do
|
76
|
+
json.title "Merge HOWTO"
|
77
|
+
json.merge! hash
|
78
|
+
end
|
79
|
+
|
80
|
+
# => "post": { "title": "Merge HOWTO", "author": { "name": "David" } }
|
81
|
+
```
|
82
|
+
|
70
83
|
Top level arrays can be handled directly. Useful for index and other collection actions.
|
71
84
|
|
72
85
|
``` ruby
|
@@ -143,7 +156,6 @@ if current_user.admin?
|
|
143
156
|
end
|
144
157
|
```
|
145
158
|
|
146
|
-
|
147
159
|
You can use partials as well. The following will render the file
|
148
160
|
`views/comments/_comments.json.jbuilder`, and set a local variable
|
149
161
|
`comments` with all this message's comments, which you can use inside
|
@@ -171,6 +183,25 @@ json.partial! partial: 'posts/post', collection: @posts, as: :post
|
|
171
183
|
json.comments @post.comments, partial: 'comments/comment', as: :comment
|
172
184
|
```
|
173
185
|
|
186
|
+
The `as: :some_symbol` is used with partials. It will take care of mapping the passed in object to a variable for the partial. If the value is a collection (either implicitly or explicitly by using the `collection:` option, then each value of the collection is passed to the partial as the variable `some_symbol`. If the value is a singular object, then the object is passed to the partial as the variable `some_symbol`.
|
187
|
+
|
188
|
+
Be sure not to confuse the `as:` option to mean nesting of the partial. For example:
|
189
|
+
|
190
|
+
```ruby
|
191
|
+
# Use the default `views/comments/_comment.json.jbuilder`, putting @comment as the comment local variable.
|
192
|
+
# Note, `comment` attributes are "inlined".
|
193
|
+
json.partial! @comment, as: :comment
|
194
|
+
```
|
195
|
+
|
196
|
+
is quite different than:
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
# comment attributes are nested under a "comment" property
|
200
|
+
json.comment do
|
201
|
+
json.partial! "/comments/comment.json.jbuilder", comment: @comment
|
202
|
+
end
|
203
|
+
```
|
204
|
+
|
174
205
|
You can pass any objects into partial templates with or without `:locals` option.
|
175
206
|
|
176
207
|
```ruby
|
@@ -243,21 +274,6 @@ environment.rb for example):
|
|
243
274
|
Jbuilder.key_format camelize: :lower
|
244
275
|
```
|
245
276
|
|
246
|
-
Faster JSON backends
|
247
|
-
--------------------
|
248
|
-
|
249
|
-
Jbuilder uses MultiJson, which by default will use the JSON gem. That gem is
|
250
|
-
currently tangled with ActiveSupport's all-Ruby `#to_json` implementation,
|
251
|
-
which is slow (fixed in Rails >= 4.1). For faster Jbuilder rendering, you can
|
252
|
-
specify something like the Yajl JSON generator instead. You'll need to include
|
253
|
-
the `yajl-ruby` gem in your Gemfile and then set the following configuration
|
254
|
-
for MultiJson:
|
255
|
-
|
256
|
-
``` ruby
|
257
|
-
require 'multi_json'
|
258
|
-
MultiJson.use :yajl
|
259
|
-
```
|
260
|
-
|
261
277
|
## Contributing to Jbuilder
|
262
278
|
|
263
279
|
Jbuilder is the work of many contributors. You're encouraged to submit pull requests, propose
|
data/gemfiles/rails_5_0.gemfile
CHANGED
data/gemfiles/rails_5_1.gemfile
CHANGED
@@ -5,9 +5,6 @@ source "https://rubygems.org"
|
|
5
5
|
gem "rake"
|
6
6
|
gem "mocha", require: false
|
7
7
|
gem "appraisal"
|
8
|
-
gem "
|
9
|
-
gem "railties", ">= 5.1.0", "< 5.2"
|
10
|
-
gem "actionpack", ">= 5.1.0", "< 5.2"
|
11
|
-
gem "activemodel", ">= 5.1.0", "< 5.2"
|
8
|
+
gem "rails", "~> 5.1.0"
|
12
9
|
|
13
10
|
gemspec path: "../"
|
data/jbuilder.gemspec
CHANGED
@@ -1,16 +1,21 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'jbuilder'
|
3
|
-
s.version = '2.
|
3
|
+
s.version = '2.10.2'
|
4
4
|
s.authors = 'David Heinemeier Hansson'
|
5
5
|
s.email = 'david@basecamp.com'
|
6
6
|
s.summary = 'Create JSON structures via a Builder-style DSL'
|
7
7
|
s.homepage = 'https://github.com/rails/jbuilder'
|
8
8
|
s.license = 'MIT'
|
9
9
|
|
10
|
-
s.required_ruby_version = '>=
|
10
|
+
s.required_ruby_version = '>= 2.2.2'
|
11
11
|
|
12
|
-
s.add_dependency 'activesupport', '>=
|
13
|
-
|
12
|
+
s.add_dependency 'activesupport', '>= 5.0.0'
|
13
|
+
|
14
|
+
if RUBY_ENGINE == 'rbx'
|
15
|
+
s.add_development_dependency('racc')
|
16
|
+
s.add_development_dependency('json')
|
17
|
+
s.add_development_dependency('rubysl')
|
18
|
+
end
|
14
19
|
|
15
20
|
s.files = `git ls-files`.split("\n")
|
16
21
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
@@ -10,6 +10,8 @@ module Rails
|
|
10
10
|
|
11
11
|
argument :attributes, type: :array, default: [], banner: 'field:type field:type'
|
12
12
|
|
13
|
+
class_option :timestamps, type: :boolean, default: true
|
14
|
+
|
13
15
|
def create_root_folder
|
14
16
|
path = File.join('app/views', controller_file_path)
|
15
17
|
empty_directory path unless File.directory?(path)
|
@@ -33,8 +35,12 @@ module Rails
|
|
33
35
|
[name, :json, :jbuilder] * '.'
|
34
36
|
end
|
35
37
|
|
36
|
-
def
|
37
|
-
|
38
|
+
def full_attributes_list
|
39
|
+
if options[:timestamps]
|
40
|
+
attributes_list(attributes_names + %w(created_at updated_at))
|
41
|
+
else
|
42
|
+
attributes_list(attributes_names)
|
43
|
+
end
|
38
44
|
end
|
39
45
|
|
40
46
|
def attributes_list(attributes = attributes_names)
|
@@ -7,6 +7,12 @@ module Rails
|
|
7
7
|
source_paths << File.expand_path('../templates', __FILE__)
|
8
8
|
|
9
9
|
hook_for :jbuilder, type: :boolean, default: true
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def permitted_params
|
14
|
+
attributes_names.map { |name| ":#{name}" }.join(', ')
|
15
|
+
end unless private_method_defined? :permitted_params
|
10
16
|
end
|
11
17
|
end
|
12
18
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
<% if namespaced? -%>
|
2
|
-
require_dependency "<%=
|
2
|
+
require_dependency "<%= namespaced_path %>/application_controller"
|
3
3
|
|
4
4
|
<% end -%>
|
5
5
|
<% module_namespacing do -%>
|
6
6
|
class <%= controller_class_name %>Controller < ApplicationController
|
7
|
-
before_action :set_<%= singular_table_name %>, only: [
|
7
|
+
before_action :set_<%= singular_table_name %>, only: %w[ show update destroy ]
|
8
8
|
|
9
9
|
# GET <%= route_url %>
|
10
10
|
# GET <%= route_url %>.json
|
@@ -51,12 +51,12 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
51
51
|
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
52
52
|
end
|
53
53
|
|
54
|
-
#
|
54
|
+
# Only allow a list of trusted parameters through.
|
55
55
|
def <%= "#{singular_table_name}_params" %>
|
56
56
|
<%- if attributes_names.empty? -%>
|
57
57
|
params.fetch(<%= ":#{singular_table_name}" %>, {})
|
58
58
|
<%- else -%>
|
59
|
-
params.require(<%= ":#{singular_table_name}" %>).permit(<%=
|
59
|
+
params.require(<%= ":#{singular_table_name}" %>).permit(<%= permitted_params %>)
|
60
60
|
<%- end -%>
|
61
61
|
end
|
62
62
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
<% if namespaced? -%>
|
2
|
-
require_dependency "<%=
|
2
|
+
require_dependency "<%= namespaced_path %>/application_controller"
|
3
3
|
|
4
4
|
<% end -%>
|
5
5
|
<% module_namespacing do -%>
|
6
6
|
class <%= controller_class_name %>Controller < ApplicationController
|
7
|
-
before_action :set_<%= singular_table_name %>, only: [
|
7
|
+
before_action :set_<%= singular_table_name %>, only: %w[ show edit update destroy ]
|
8
8
|
|
9
9
|
# GET <%= route_url %>
|
10
10
|
# GET <%= route_url %>.json
|
@@ -33,10 +33,10 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
33
33
|
|
34
34
|
respond_to do |format|
|
35
35
|
if @<%= orm_instance.save %>
|
36
|
-
format.html { redirect_to @<%= singular_table_name %>, notice: <%= "
|
36
|
+
format.html { redirect_to @<%= singular_table_name %>, notice: <%= %("#{human_name} was successfully created.") %> }
|
37
37
|
format.json { render :show, status: :created, location: <%= "@#{singular_table_name}" %> }
|
38
38
|
else
|
39
|
-
format.html { render :new }
|
39
|
+
format.html { render :new, status: :unprocessable_entity }
|
40
40
|
format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
|
41
41
|
end
|
42
42
|
end
|
@@ -47,10 +47,10 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
47
47
|
def update
|
48
48
|
respond_to do |format|
|
49
49
|
if @<%= orm_instance.update("#{singular_table_name}_params") %>
|
50
|
-
format.html { redirect_to @<%= singular_table_name %>, notice: <%= "
|
50
|
+
format.html { redirect_to @<%= singular_table_name %>, notice: <%= %("#{human_name} was successfully updated.") %> }
|
51
51
|
format.json { render :show, status: :ok, location: <%= "@#{singular_table_name}" %> }
|
52
52
|
else
|
53
|
-
format.html { render :edit }
|
53
|
+
format.html { render :edit, status: :unprocessable_entity }
|
54
54
|
format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
|
55
55
|
end
|
56
56
|
end
|
@@ -61,7 +61,7 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
61
61
|
def destroy
|
62
62
|
@<%= orm_instance.destroy %>
|
63
63
|
respond_to do |format|
|
64
|
-
format.html { redirect_to <%= index_helper %>_url, notice: <%= "
|
64
|
+
format.html { redirect_to <%= index_helper %>_url, notice: <%= %("#{human_name} was successfully destroyed.") %> }
|
65
65
|
format.json { head :no_content }
|
66
66
|
end
|
67
67
|
end
|
@@ -72,12 +72,12 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
72
72
|
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
73
73
|
end
|
74
74
|
|
75
|
-
#
|
75
|
+
# Only allow a list of trusted parameters through.
|
76
76
|
def <%= "#{singular_table_name}_params" %>
|
77
77
|
<%- if attributes_names.empty? -%>
|
78
78
|
params.fetch(<%= ":#{singular_table_name}" %>, {})
|
79
79
|
<%- else -%>
|
80
|
-
params.require(<%= ":#{singular_table_name}" %>).permit(<%=
|
80
|
+
params.require(<%= ":#{singular_table_name}" %>).permit(<%= permitted_params %>)
|
81
81
|
<%- end -%>
|
82
82
|
end
|
83
83
|
end
|
@@ -1 +1 @@
|
|
1
|
-
json.array! @<%= plural_table_name %>, partial:
|
1
|
+
json.array! @<%= plural_table_name %>, partial: "<%= plural_table_name %>/<%= singular_table_name %>", as: :<%= singular_table_name %>
|
@@ -1,2 +1,2 @@
|
|
1
|
-
json.extract! <%= singular_table_name %>, <%=
|
1
|
+
json.extract! <%= singular_table_name %>, <%= full_attributes_list %>
|
2
2
|
json.url <%= singular_table_name %>_url(<%= singular_table_name %>, format: :json)
|
@@ -73,8 +73,8 @@ class JbuilderTemplate < Jbuilder
|
|
73
73
|
# json.cache_if! !admin?, @person, expires_in: 10.minutes do
|
74
74
|
# json.extract! @person, :name, :age
|
75
75
|
# end
|
76
|
-
def cache_if!(condition, *args)
|
77
|
-
condition ? cache!(*args,
|
76
|
+
def cache_if!(condition, *args, &block)
|
77
|
+
condition ? cache!(*args, &block) : yield
|
78
78
|
end
|
79
79
|
|
80
80
|
def target!
|
@@ -104,7 +104,7 @@ class JbuilderTemplate < Jbuilder
|
|
104
104
|
private
|
105
105
|
|
106
106
|
def _render_partial_with_options(options)
|
107
|
-
options.reverse_merge! locals:
|
107
|
+
options.reverse_merge! locals: options.except(:partial, :as, :collection)
|
108
108
|
options.reverse_merge! ::JbuilderTemplate.template_lookup_options
|
109
109
|
as = options[:as]
|
110
110
|
|
@@ -151,8 +151,8 @@ class JbuilderTemplate < Jbuilder
|
|
151
151
|
name_options = options.slice(:skip_digest, :virtual_path)
|
152
152
|
key = _fragment_name_with_digest(key, name_options)
|
153
153
|
|
154
|
-
if @context.respond_to?(:
|
155
|
-
key = @context.
|
154
|
+
if @context.respond_to?(:combined_fragment_cache_key)
|
155
|
+
key = @context.combined_fragment_cache_key(key)
|
156
156
|
else
|
157
157
|
key = url_for(key).split('://', 2).last if ::Hash === key
|
158
158
|
end
|
@@ -164,7 +164,7 @@ class JbuilderTemplate < Jbuilder
|
|
164
164
|
if @context.respond_to?(:cache_fragment_name)
|
165
165
|
# Current compatibility, fragment_name_with_digest is private again and cache_fragment_name
|
166
166
|
# should be used instead.
|
167
|
-
@context.cache_fragment_name(key, options)
|
167
|
+
@context.cache_fragment_name(key, **options)
|
168
168
|
elsif @context.respond_to?(:fragment_name_with_digest)
|
169
169
|
# Backwards compatibility for period of time when fragment_name_with_digest was made public.
|
170
170
|
@context.fragment_name_with_digest(key)
|
@@ -222,11 +222,12 @@ end
|
|
222
222
|
|
223
223
|
class JbuilderHandler
|
224
224
|
cattr_accessor :default_format
|
225
|
-
self.default_format =
|
225
|
+
self.default_format = :json
|
226
226
|
|
227
|
-
def self.call(template)
|
227
|
+
def self.call(template, source = nil)
|
228
|
+
source ||= template.source
|
228
229
|
# this juggling is required to keep line numbers right in the error
|
229
|
-
%{__already_defined = defined?(json); json||=JbuilderTemplate.new(self); #{
|
230
|
+
%{__already_defined = defined?(json); json||=JbuilderTemplate.new(self); #{source}
|
230
231
|
json.target! unless (__already_defined && __already_defined != "method")}
|
231
232
|
end
|
232
233
|
end
|