active_record_api-rest 1.0.10 → 1.0.11

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
2
  SHA256:
3
- metadata.gz: 5725a7eed108dec0d342fede5c8c2009f4eb34fd00f66ee5bc320ac72d8bd596
4
- data.tar.gz: 72f6903479ce6fc8b2a7f37d583cdb55f9ac039aea541ff76e312d2a755fd024
3
+ metadata.gz: 4ab132ecc0b2f3ccd7c4c151674e9c2623450c674fb88aee69e4277f9510a7ba
4
+ data.tar.gz: d2e16fa7cb20a80c1104f2f71f576a0791e585d52e8f227d54eb3d79472d0417
5
5
  SHA512:
6
- metadata.gz: 80fda6094d96f54182dc0f137296d7f9400b553aca15e7c408267ec85b91acce507b67b062eccc5603159c9628f63b7790c8b54db6a28a933eb0b8a398ba7c7b
7
- data.tar.gz: 0b41e08348262252dfa058d03aafeed3fb5e83c454e1ea0751058b022599b78b8634cd00ac293b9706332830206f91105bd17cd458f1224ca19ef2bb5429b065
6
+ metadata.gz: 6bbd71ac2d4987ac9c54a3eb840d71b536959c1f47aa1116124a4f805477e1c4f0300548ab28714ba1f14338156dcaf202662d18bf4cf62aa046b66f66db5798
7
+ data.tar.gz: c22e0faaae9fea5191fdf34449368fe8533ca85de1fe7111bb6aa6b8c419ae5bb6782cfaa357bfd186fbf6bc163134154524249886b8bd0e65e192e03ab4dac0
@@ -24,7 +24,7 @@ module ActiveRecordApi
24
24
  end
25
25
 
26
26
  def update
27
- if model.update(resource_params)
27
+ if model.update(filtered_params)
28
28
  redirect_to_model
29
29
  else
30
30
  render json: model.errors, status: :unprocessable_entity
@@ -39,7 +39,11 @@ module ActiveRecordApi
39
39
  protected
40
40
 
41
41
  def redirect_to_model
42
- redirect_to "#{protocol}://#{request.host_with_port}#{request.path}/#{model.id}", status: :see_other
42
+ if request.path.include?(model.id)
43
+ redirect_to "#{protocol}#{request.host_with_port}#{request.path}", status: :see_other
44
+ else
45
+ redirect_to "#{protocol}#{request.host_with_port}#{request.path}/#{model.id}", status: :see_other
46
+ end
43
47
  end
44
48
 
45
49
  def protocol
@@ -52,14 +56,8 @@ module ActiveRecordApi
52
56
  render json: { base: "Extra parameters are not allow: #{not_allowed_params.join(', ')}" }, status: :unprocessable_entity
53
57
  end
54
58
 
55
- def resource_params
56
- @resource_params ||= filtered_params.reject do |column_name|
57
- column_name.to_s == 'id'
58
- end
59
- end
60
-
61
59
  def not_allowed_params
62
- @not_allowed_params ||= ((params.keys.map(&:to_sym) - [:controller, :action, :id, controller_name.singularize.to_sym]) - resource_params.keys.map(&:to_sym))
60
+ @not_allowed_params ||= ((params.keys.map(&:to_sym) - [:controller, :action, :id, :created_at, :updated_at, controller_name.singularize.to_sym]) - filtered_params.keys.map(&:to_sym))
63
61
  end
64
62
 
65
63
  def load_model
@@ -80,7 +78,7 @@ module ActiveRecordApi
80
78
  end
81
79
 
82
80
  def filtered_params
83
- @filtered_params ||= params.permit(allowed_params).to_h
81
+ @simple_params = params.permit!.to_h.select! { |key, _value| allowed_params.include?(key.to_sym) }
84
82
  end
85
83
 
86
84
  def allowed_params
@@ -92,7 +90,7 @@ module ActiveRecordApi
92
90
  else
93
91
  col
94
92
  end
95
- end
93
+ end - %i[created_at updated_at id]
96
94
  end
97
95
 
98
96
  def column_definition(column_name)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveRecordApi
4
4
  module Rest
5
- VERSION = '1.0.10'.freeze
5
+ VERSION = '1.0.11'.freeze
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_api-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Full Measure Education
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-09 00:00:00.000000000 Z
11
+ date: 2019-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler