jbuilder 2.6.4 → 2.11.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e35bd234795a5d5f23c73a30d259ca195e42f6e5
4
- data.tar.gz: 3e884978c900ea0ef14aa7e68e611246b2b74814
2
+ SHA256:
3
+ metadata.gz: 3e3eebf3fe3849616361ae7df9556f466eaf84da813756b8690dfbd5c28d41a1
4
+ data.tar.gz: 011c0162b09a94f229673e88bab0d0d466d9552a004afb426f817a02c3af8943
5
5
  SHA512:
6
- metadata.gz: de29407995773a316901cee9012d9f363366ac02ecd4faeb98ab58099536dc5377d53e3c07242f24f17e039111a7f45842ecb5cfc37be67af5852e4ce7c471de
7
- data.tar.gz: 9bc528a7c2f5fe784567d0d62012a51b3e398debf13a72e68496f7345be69f0f62c401b6dfa07e1a38773a4d4d952b768e63b83c32fa24e64041fe62b6dd3778
6
+ metadata.gz: 29968e2f35da52dc00db229d0085d77a7d390417bbe3011b005824ff45a1291bca0f45c59d4f40263a3ac236e31ea3fdd0cd78ba01ddef4e51414aea4ac34704
7
+ data.tar.gz: '09df7fb01ce2d128b0f45116cc4f2ccb01469031a51b598f6c17c16f58ddbd0c3059095a1a6761a2f26e328b3960def55752d6ed36cca0e2952e393d712e48b3'
data/.gitignore CHANGED
@@ -1,5 +1,7 @@
1
1
  tmp
2
+ gemfiles/.bundle
2
3
  gemfiles/*.lock
3
4
  Gemfile.lock
4
5
  .ruby-version
5
6
  pkg
7
+ *.gem
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
- - 1.9
8
- - 2.0
9
- - 2.1
10
- - 2.2.5
11
- - 2.3.1
12
- - 2.4.0
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.9
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: jruby-19mode
47
- gemfile: gemfiles/rails_5_0.gemfile
48
- - rvm: jruby-19mode
49
- gemfile: gemfiles/rails_5_1.gemfile
50
- - rvm: rbx
51
- gemfile: gemfiles/rails_5_0.gemfile
52
- - rvm: rbx
53
- gemfile: gemfiles/rails_5_1.gemfile
54
- - rvm: 2.4.0
55
- gemfile: gemfiles/rails_3_0.gemfile
56
- - rvm: 2.4.0
57
- gemfile: gemfiles/rails_3_1.gemfile
58
- - rvm: 2.4.0
59
- gemfile: gemfiles/rails_3_2.gemfile
60
- - rvm: 2.4.0
61
- gemfile: gemfiles/rails_4_0.gemfile
62
- - rvm: 2.4.0
63
- gemfile: gemfiles/rails_4_1.gemfile
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,50 +1,21 @@
1
- appraise "rails-3-0" do
2
- gem "test-unit"
3
- gem "railties", "~> 3.0.0"
4
- gem "actionpack", "~> 3.0.0"
5
- gem "activemodel", "~> 3.0.0"
6
- end
7
-
8
- appraise "rails-3-1" do
9
- gem "test-unit"
10
- gem "railties", "~> 3.1.0"
11
- gem "actionpack", "~> 3.1.0"
12
- gem "activemodel", "~> 3.1.0"
13
- end
14
-
15
- appraise "rails-3-2" do
16
- gem "test-unit"
17
- gem "railties", "~> 3.2.0"
18
- gem "actionpack", "~> 3.2.0"
19
- gem "activemodel", "~> 3.2.0"
20
- end
21
-
22
- appraise "rails-4-0" do
23
- gem "railties", "~> 4.0.0"
24
- gem "actionpack", "~> 4.0.0"
25
- gem "activemodel", "~> 4.0.0"
1
+ appraise "rails-5-0" do
2
+ gem "rails", "~> 5.0.0"
26
3
  end
27
4
 
28
- appraise "rails-4-1" do
29
- gem "railties", "~> 4.1.0"
30
- gem "actionpack", "~> 4.1.0"
31
- gem "activemodel", "~> 4.1.0"
5
+ appraise "rails-5-1" do
6
+ gem "rails", "~> 5.1.0"
32
7
  end
33
8
 
34
- appraise "rails-4-2" do
35
- gem "railties", "~> 4.2.0"
36
- gem "actionpack", "~> 4.2.0"
37
- gem "activemodel", "~> 4.2.0"
9
+ appraise "rails-5-2" do
10
+ gem "rails", "~> 5.2.0"
38
11
  end
39
12
 
40
- appraise "rails-5-0" do
41
- gem "railties", "~> 5.0.0"
42
- gem "actionpack", "~> 5.0.0"
43
- gem "activemodel", "~> 5.0.0"
44
- end
13
+ if RUBY_VERSION >= "2.5.0"
14
+ appraise "rails-6-0" do
15
+ gem "rails", "~> 6.0.0"
16
+ end
45
17
 
46
- appraise "rails-5-1" do
47
- gem "railties", ">= 5.1.0", "< 5.2"
48
- gem "actionpack", ">= 5.1.0", "< 5.2"
49
- gem "activemodel", ">= 5.1.0", "< 5.2"
18
+ appraise "rails-head" do
19
+ gem "rails", github: "rails/rails"
20
+ end
50
21
  end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,62 @@
1
1
  # Changelog
2
2
 
3
+ 2.11.1
4
+ ------
5
+
6
+ * Use symbols instead of strings for before_action fitlers [DHH]
7
+ * Slim down comments in generated scaffold code [DHH]
8
+
9
+ 2.11.0
10
+ ------
11
+
12
+ * [Allow jbuilder instance to be passed to #merge!](https://github.com/rails/jbuilder/pull/485)
13
+ * [Fix for key_format! when using nested hashes](https://github.com/rails/jbuilder/pull/486)
14
+ * [Include rich_text, attachment, and attachments fields in json partial](https://github.com/rails/jbuilder/pull/459)
15
+
16
+ 2.10.2
17
+ ------
18
+
19
+ * Update scaffold generator to use double quotes, 422 form error responds, and modern string-of-arrays syntax [DHH]
20
+
21
+ 2.10.1
22
+ ------
23
+
24
+ * Fix keyword arguments warning on Ruby 2.7
25
+
26
+ 2.10.0
27
+ ------
28
+
29
+ * Requires Rails 5+ and Ruby 2.2+
30
+ * Nested hashes are deep-merged
31
+
32
+ 2.9.1
33
+ -----
34
+
35
+ * [Respect JSON encoding customizations](https://github.com/rails/jbuilder/commit/e2e8623b08078ad6a2323ce8ecaf642b7afe1166)
36
+
37
+ 2.9.0
38
+ -----
39
+
40
+ * [Fix passing object with partial without locals](https://github.com/rails/jbuilder/pull/435)
41
+ * [Fix deprecation warning in Rails 6.0](https://github.com/rails/jbuilder/pull/453)
42
+ * [Use quotes consistently in generated templates](https://github.com/rails/jbuilder/pull/455)
43
+ * [Allow omitting timestamps from generated partials](https://github.com/rails/jbuilder/pull/448)
44
+ * [Respect changing scaffold generator](https://github.com/rails/jbuilder/pull/458)
45
+ * [Use a symbolic default format for Rails 6.0 forward compatibility](https://github.com/rails/jbuilder/commit/3895a7243f3db292b0bf15513fc05494e6e50576)
46
+ * [Drop MultiJSON in favor of Ruby standard library JSON](https://github.com/rails/jbuilder/commit/b952ae096eb1828b0fcfde06e6ba62311494ec49)
47
+
48
+ 2.8.0
49
+ -----
50
+
51
+ * [Replace deprecated fragment_cache_key for Rails 5.2 support](https://github.com/rails/jbuilder/pull/430)
52
+
53
+ 2.7.0
54
+ -----
55
+
56
+ * [Requires Rails 4+](https://github.com/rails/jbuilder/commit/5207ff394533177fffdd768bfaa6413a0cd16dc8)
57
+ * [Fix implicitly rendering a JSON partial with the same name as an
58
+ HTML partial](https://github.com/rails/jbuilder/pull/400)
59
+
3
60
  2.6.4
4
61
  -----
5
62
 
data/CONTRIBUTING.md CHANGED
@@ -4,18 +4,16 @@ Contributing to Jbuilder
4
4
  [![Build Status](https://api.travis-ci.org/rails/jbuilder.svg?branch=master)][travis]
5
5
  [![Gem Version](https://badge.fury.io/rb/jbuilder.svg)][gem]
6
6
  [![Code Climate](https://codeclimate.com/github/rails/jbuilder/badges/gpa.svg)][codeclimate]
7
- [![Dependencies Status](https://gemnasium.com/rails/jbuilder.svg)][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
 
16
14
  #### Fork the Project
17
15
 
18
- Fork the [project on Github](https://github.com/rails/jbuilder) and check out your copy.
16
+ Fork the [project on GitHub](https://github.com/rails/jbuilder) and check out your copy.
19
17
 
20
18
  ```
21
19
  git clone https://github.com/contributor/jbuilder.git
data/Gemfile CHANGED
@@ -5,4 +5,3 @@ gemspec
5
5
  gem "rake"
6
6
  gem "mocha", require: false
7
7
  gem "appraisal"
8
- gem "pry"
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011-2017 David Heinemeier Hansson, 37signals
1
+ Copyright (c) 2011-2018 David Heinemeier Hansson, 37signals
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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/Rakefile CHANGED
@@ -12,11 +12,7 @@ else
12
12
 
13
13
  test.libs << "test"
14
14
 
15
- if Rails::VERSION::MAJOR == 3
16
- test.test_files = %w[test/jbuilder_template_test.rb test/jbuilder_test.rb]
17
- else
18
- test.test_files = FileList["test/*_test.rb"]
19
- end
15
+ test.test_files = FileList["test/*_test.rb"]
20
16
  end
21
17
 
22
18
  task default: :test
@@ -3,11 +3,8 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rake"
6
- gem "mocha", :require => false
6
+ gem "mocha", require: false
7
7
  gem "appraisal"
8
- gem "pry"
9
- gem "railties", "~> 5.0.0"
10
- gem "actionpack", "~> 5.0.0"
11
- gem "activemodel", "~> 5.0.0"
8
+ gem "rails", "~> 5.0.0"
12
9
 
13
- gemspec :path => "../"
10
+ gemspec path: "../"
@@ -3,11 +3,8 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rake"
6
- gem "mocha", :require => false
6
+ gem "mocha", require: false
7
7
  gem "appraisal"
8
- gem "pry"
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
- gemspec :path => "../"
10
+ gemspec path: "../"
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake"
6
+ gem "mocha", require: false
7
+ gem "appraisal"
8
+ gem "rails", "~> 5.2.0"
9
+
10
+ gemspec path: "../"
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake"
6
+ gem "mocha", require: false
7
+ gem "appraisal"
8
+ gem "rails", "~> 6.0.0"
9
+
10
+ gemspec path: "../"
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake"
6
+ gem "mocha", require: false
7
+ gem "appraisal"
8
+ gem "rails", github: "rails/rails"
9
+
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.6.4'
4
- s.authors = ['David Heinemeier Hansson']
5
- s.email = ['david@37signals.com']
3
+ s.version = '2.11.1'
4
+ s.authors = 'David Heinemeier Hansson'
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 = '>= 1.9.3'
10
+ s.required_ruby_version = '>= 2.2.2'
11
11
 
12
- s.add_dependency 'activesupport', '>= 3.0.0'
13
- s.add_dependency 'multi_json', '>= 1.2'
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 attributes_list_with_timestamps
37
- attributes_list(attributes_names + %w(created_at updated_at))
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)
@@ -44,6 +50,10 @@ module Rails
44
50
 
45
51
  attributes.map { |a| ":#{a}"} * ', '
46
52
  end
53
+
54
+ def virtual_attributes
55
+ attributes.select {|name| name.respond_to?(:virtual?) && name.virtual? }
56
+ end
47
57
  end
48
58
  end
49
59
  end
@@ -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 "<%= namespaced_file_path %>/application_controller"
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: [:show, :update, :destroy]
7
+ before_action :set_<%= singular_table_name %>, only: %i[ 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
- # Never trust parameters from the scary internet, only allow the white list through.
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(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
59
+ params.require(<%= ":#{singular_table_name}" %>).permit(<%= permitted_params %>)
60
60
  <%- end -%>
61
61
  end
62
62
  end
@@ -1,19 +1,17 @@
1
1
  <% if namespaced? -%>
2
- require_dependency "<%= namespaced_file_path %>/application_controller"
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: [:show, :edit, :update, :destroy]
7
+ before_action :set_<%= singular_table_name %>, only: %i[ show edit update destroy ]
8
8
 
9
- # GET <%= route_url %>
10
- # GET <%= route_url %>.json
9
+ # GET <%= route_url %> or <%= route_url %>.json
11
10
  def index
12
11
  @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
13
12
  end
14
13
 
15
- # GET <%= route_url %>/1
16
- # GET <%= route_url %>/1.json
14
+ # GET <%= route_url %>/1 or <%= route_url %>/1.json
17
15
  def show
18
16
  end
19
17
 
@@ -26,42 +24,39 @@ class <%= controller_class_name %>Controller < ApplicationController
26
24
  def edit
27
25
  end
28
26
 
29
- # POST <%= route_url %>
30
- # POST <%= route_url %>.json
27
+ # POST <%= route_url %> or <%= route_url %>.json
31
28
  def create
32
29
  @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
33
30
 
34
31
  respond_to do |format|
35
32
  if @<%= orm_instance.save %>
36
- format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully created.'" %> }
33
+ format.html { redirect_to @<%= singular_table_name %>, notice: <%= %("#{human_name} was successfully created.") %> }
37
34
  format.json { render :show, status: :created, location: <%= "@#{singular_table_name}" %> }
38
35
  else
39
- format.html { render :new }
36
+ format.html { render :new, status: :unprocessable_entity }
40
37
  format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
41
38
  end
42
39
  end
43
40
  end
44
41
 
45
- # PATCH/PUT <%= route_url %>/1
46
- # PATCH/PUT <%= route_url %>/1.json
42
+ # PATCH/PUT <%= route_url %>/1 or <%= route_url %>/1.json
47
43
  def update
48
44
  respond_to do |format|
49
45
  if @<%= orm_instance.update("#{singular_table_name}_params") %>
50
- format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %> }
46
+ format.html { redirect_to @<%= singular_table_name %>, notice: <%= %("#{human_name} was successfully updated.") %> }
51
47
  format.json { render :show, status: :ok, location: <%= "@#{singular_table_name}" %> }
52
48
  else
53
- format.html { render :edit }
49
+ format.html { render :edit, status: :unprocessable_entity }
54
50
  format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
55
51
  end
56
52
  end
57
53
  end
58
54
 
59
- # DELETE <%= route_url %>/1
60
- # DELETE <%= route_url %>/1.json
55
+ # DELETE <%= route_url %>/1 or <%= route_url %>/1.json
61
56
  def destroy
62
57
  @<%= orm_instance.destroy %>
63
58
  respond_to do |format|
64
- format.html { redirect_to <%= index_helper %>_url, notice: <%= "'#{human_name} was successfully destroyed.'" %> }
59
+ format.html { redirect_to <%= index_helper %>_url, notice: <%= %("#{human_name} was successfully destroyed.") %> }
65
60
  format.json { head :no_content }
66
61
  end
67
62
  end
@@ -72,12 +67,12 @@ class <%= controller_class_name %>Controller < ApplicationController
72
67
  @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
73
68
  end
74
69
 
75
- # Never trust parameters from the scary internet, only allow the white list through.
70
+ # Only allow a list of trusted parameters through.
76
71
  def <%= "#{singular_table_name}_params" %>
77
72
  <%- if attributes_names.empty? -%>
78
73
  params.fetch(<%= ":#{singular_table_name}" %>, {})
79
74
  <%- else -%>
80
- params.require(<%= ":#{singular_table_name}" %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
75
+ params.require(<%= ":#{singular_table_name}" %>).permit(<%= permitted_params %>)
81
76
  <%- end -%>
82
77
  end
83
78
  end
@@ -1 +1 @@
1
- json.array! @<%= plural_table_name %>, partial: '<%= plural_table_name %>/<%= singular_table_name %>', as: :<%= singular_table_name %>
1
+ json.array! @<%= plural_table_name %>, partial: "<%= plural_table_name %>/<%= singular_table_name %>", as: :<%= singular_table_name %>
@@ -1,2 +1,16 @@
1
- json.extract! <%= singular_table_name %>, <%= attributes_list_with_timestamps %>
1
+ json.extract! <%= singular_table_name %>, <%= full_attributes_list %>
2
2
  json.url <%= singular_table_name %>_url(<%= singular_table_name %>, format: :json)
3
+ <%- virtual_attributes.each do |attribute| -%>
4
+ <%- if attribute.type == :rich_text -%>
5
+ json.<%= attribute.name %> <%= singular_table_name %>.<%= attribute.name %>.to_s
6
+ <%- elsif attribute.type == :attachment -%>
7
+ json.<%= attribute.name %> url_for(<%= singular_table_name %>.<%= attribute.name %>)
8
+ <%- elsif attribute.type == :attachments -%>
9
+ json.<%= attribute.name %> do
10
+ json.array!(<%= singular_table_name %>.<%= attribute.name %>) do |<%= attribute.singular_name %>|
11
+ json.id <%= attribute.singular_name %>.id
12
+ json.url url_for(<%= attribute.singular_name %>)
13
+ end
14
+ end
15
+ <%- end -%>
16
+ <%- end -%>