mini_defender 0.3.11 → 0.3.13

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: 7cdbaf1ca9c6da27dc125f3585d2c4e73e638794cb87d8ad5f983a9532e85af6
4
- data.tar.gz: 440a52ff11491cefacc033e958d1b43b7d6d7805cbff618a5f718d1dabe83cde
3
+ metadata.gz: 1fb38a701337253718887e5d325fbc353b15959d3dfb66401aca722175e407da
4
+ data.tar.gz: 46dcb917d9d66e10344641313af7a498cac609c9e08369dfc617457e2e1706f6
5
5
  SHA512:
6
- metadata.gz: 462bbdac39c0a28b1596243c1a0e252217f191ef32bf135efa661692a9f58e280da94a550ab7c3dddcae621f6b5b65fb81ba691ae5d6dffdf917a2a6f8c18009
7
- data.tar.gz: f61ca0aab03eaa52e315dab83c83de263882d2281adcdb4ce7d73d03132f4909353b2c174f7d6207797f1fc949dfb2257695645c17d39f5ca31fb4dcbe6e4290
6
+ metadata.gz: 5ccf6dfcf0503020f603f8afdd33644a1d13d73bd56f5fd58706895c76b7e0a0d792a3644472fad2083a2135c2c3fb682cbf610838e9f7c6908d606266d04317
7
+ data.tar.gz: 99fa8973a9cf335861e6e6e7b0522897831c0f67b779c4816956552ec8fb5e3a52e71522c95c7794e26a5b6e0a8178a5a2db72801b772c1dbac657cc3f645df7
@@ -10,13 +10,17 @@ module MiniDefender::HandlesValidationErrors
10
10
  private
11
11
 
12
12
  def handle_validation_error(error)
13
+ unless self.respond_to?(:respond_to)
14
+ render json: { message: error.message, errors: error.errors }, status: :unprocessable_entity
15
+ end
16
+
13
17
  respond_to do |format|
14
18
  format.html do
15
19
  flash[:error] = error.message
16
20
  flash[:validation_errors] = error.errors
17
21
  flash[:old_values] = safe_values
18
22
 
19
- redirect_back fallback_location: root_path
23
+ redirect_back fallback_location: '/'
20
24
  end
21
25
 
22
26
  format.json do
@@ -36,9 +36,17 @@ module MiniDefender::ValidationHelpers
36
36
  end
37
37
 
38
38
  def field_errors(field)
39
- raise ArgumentError, 'Expected a block.' unless block_given?
39
+ # Transform Rails foo[bar] convention to foo.bar
40
+ field = field.gsub('[', '.').gsub(']', '')
41
+
42
+ validation_errors[field] || []
43
+ end
44
+
45
+ def render_field_errors(field)
46
+ unless block_given?
47
+ raise ArgumentError, 'Expected a block.'
48
+ end
40
49
 
41
- errors = validation_errors[field] || []
42
- errors.each { |e| yield(e) }
50
+ field_errors(field).each { |e| yield(e) }
43
51
  end
44
52
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MiniDefender
4
- VERSION = "0.3.11"
4
+ VERSION = "0.3.13"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_defender
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.11
4
+ version: 0.3.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ali Alhoshaiyan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-14 00:00:00.000000000 Z
11
+ date: 2023-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport