effective_resources 0.4.2 → 0.4.3

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
  SHA1:
3
- metadata.gz: 1179bc927b2e8cd0cc3293d291aacff6ab58e6b4
4
- data.tar.gz: 5fd8f1a47e8e01aaf97f1f38568eb5a06128532d
3
+ metadata.gz: 1ea8856025d95c68494d488970226e6c212a919d
4
+ data.tar.gz: b024cdc31307bf491b9432d7bb24e84928edb16a
5
5
  SHA512:
6
- metadata.gz: f407ebc649b42b9ecbbe766621cdce2f6290dd9ebffd316da013a0d76dce7a5b2e30c7265dd8414fb56fea3e01e4598ed8c3a539f7b0dc4063b8e6a97f51c3e1
7
- data.tar.gz: ff419e84356ea9b20916dd404ed9afaf966228ed7f4c578637127f51eab77785bb5a895ef31f1d4b4f87deb3d7bbbe83b061f6811878da10c26e9ed718bc516e
6
+ metadata.gz: 80b4b4aec2b1bc80403e808e72949904c4a8d791e7c42f2f848aa4056424ea937514d3896565a1c82e53a747564f2fb0b7788ac5378e07590abf899e952218ef
7
+ data.tar.gz: 60b75dbf6e5c7cedd1448e6599090b9be54106bb6cbd1603a48fb90ada7cc8034999d1613c710e0fcc721ee67cb428032b9cd22350a28530e3299849482ce9cd
@@ -18,7 +18,7 @@ module Effective
18
18
  raise "expected @#{resource_name} to respond to #{action}!" unless resource.respond_to?("#{action}!")
19
19
 
20
20
  begin
21
- raise 'exception' unless resource.send("#{action}!")
21
+ resource.send("#{action}!") || raise('exception')
22
22
 
23
23
  flash[:success] = "Successfully #{action}#{action.to_s.end_with?('e') ? 'd' : 'ed'} #{resource_human_name}"
24
24
  redirect_back fallback_location: resource_redirect_path
@@ -130,7 +130,12 @@ module Effective
130
130
  flash[:danger] = "Unable to delete #{resource_human_name}: #{resource.errors.full_messages.to_sentence}"
131
131
  end
132
132
 
133
- request.referer.present? ? redirect_to(request.referer) : redirect_to(send(resource_index_path))
133
+ if request.referer.present? && !request.referer.include?(send(effective_resource.show_path))
134
+ redirect_to(request.referer)
135
+ else
136
+ redirect_to(send(resource_index_path))
137
+ end
138
+
134
139
  end
135
140
 
136
141
  protected
@@ -140,7 +145,10 @@ module Effective
140
145
  when 'Save' ; send(effective_resource.edit_path, resource)
141
146
  when 'Save and Continue' ; send(effective_resource.index_path)
142
147
  when 'Save and Add New' ; send(effective_resource.new_path)
143
- else send((effective_resource.show_path(check: true) || effective_resource.edit_path), resource)
148
+ when 'Save and Return'
149
+ request.referer.present? ? request.referer : send(resource_index_path)
150
+ else
151
+ send((effective_resource.show_path(check: true) || effective_resource.edit_path), resource)
144
152
  end
145
153
  end
146
154
 
@@ -1,20 +1,21 @@
1
1
  - resource = (@_effective_resource || Effective::Resource.new(controller_path))
2
- - @resource = instance_variable_get('@' + resource.name)
2
+ - @resource = instance_variable_get('@' + resource.name) if resource.name
3
3
 
4
- .row
5
- .col-sm-6
6
- %h1= @page_title
7
- .col-sm-6
8
- %p.text-right
9
- - resource.member_post_actions.each do |action|
10
- - if EffectiveResources.authorized?(controller, action.to_sym, @resource)
11
- - if resource.action_post_path(action, check: true).present?
12
- = link_to action.titleize, send(resource.action_post_path(action), @resource), class: 'btn btn-primary',
13
- data: { confirm: "Really #{action} #{@resource}?", method: :post }
4
+ - if @resource
5
+ .row
6
+ .col-sm-6
7
+ %h1= @page_title
8
+ .col-sm-6
9
+ %p.text-right
10
+ - resource.member_post_actions.each do |action|
11
+ - if EffectiveResources.authorized?(controller, action.to_sym, @resource)
12
+ - if resource.action_post_path(action, check: true).present?
13
+ = link_to action.titleize, send(resource.action_post_path(action), @resource), class: 'btn btn-primary',
14
+ data: { confirm: "Really #{action} #{@resource}?", method: :post }
14
15
 
15
- - if EffectiveResources.authorized?(controller, :destroy, @resource)
16
- - if resource.destroy_path(check: true).present?
17
- = link_to 'Delete', send(resource.destroy_path, @resource), class: 'btn btn-danger',
18
- data: { confirm: "Really delete #{@resource}?", method: :delete }
16
+ - if EffectiveResources.authorized?(controller, :destroy, @resource)
17
+ - if resource.destroy_path(check: true).present?
18
+ = link_to 'Delete', send(resource.destroy_path, @resource), class: 'btn btn-danger',
19
+ data: { confirm: "Really delete #{@resource}?", method: :delete }
19
20
 
20
- = render 'form', resource.name.to_sym => @resource
21
+ = render 'form', resource.name.to_sym => @resource
@@ -11,13 +11,13 @@
11
11
  - if @datatable
12
12
  = render_datatable(@datatable)
13
13
 
14
- - elsif instance_variable_get('@' + resource.plural_name)
14
+ - elsif instance_variable_get('@' + resource.plural_name).respond_to?(:to_partial_path)
15
15
  = render instance_variable_get('@' + resource.plural_name)
16
16
 
17
- - elsif instance_variable_get('@' + resource.name)
17
+ - elsif instance_variable_get('@' + resource.name).respond_to?(:to_partial_path)
18
18
  = render instance_variable_get('@' + resource.name)
19
19
 
20
20
  - elsif Rails.env.development?
21
21
  %p effective_resources index view is not sure what to render.
22
- %p Define an @datatable, @#{resource.plural_name}, or @#{resource.name}.
22
+ %p Define an @datatable, @#{resource.try(:plural_name) || 'a plural'}, or @#{resource.try(:name) || 'a singular'}.
23
23
  %p or include Effective::CrudController in your controller
@@ -2,4 +2,5 @@
2
2
 
3
3
  %h1= @page_title
4
4
 
5
- = render 'form', resource.name.to_sym => instance_variable_get('@' + resource.name)
5
+ - if resource.name.present? && instance_variable_get('@' + resource.name)
6
+ = render 'form', resource.name.to_sym => instance_variable_get('@' + resource.name)
@@ -1,20 +1,21 @@
1
1
  - resource = (@_effective_resource || Effective::Resource.new(controller_path))
2
- - @resource = instance_variable_get('@' + resource.name)
2
+ - @resource = instance_variable_get('@' + resource.name) if resource.name
3
3
 
4
- .row
5
- .col-sm-6
6
- %h1= @page_title
7
- .col-sm-6
8
- %p.text-right
9
- - resource.member_post_actions.each do |action|
10
- - if EffectiveResources.authorized?(controller, action.to_sym, @resource)
11
- - if resource.action_post_path(action, check: true).present?
12
- = link_to action.titleize, send(resource.action_post_path(action), @resource), class: 'btn btn-primary',
13
- data: { confirm: "Really #{action} #{@resource}?", method: :post }
4
+ - if @resource
5
+ .row
6
+ .col-sm-6
7
+ %h1= @page_title
8
+ .col-sm-6
9
+ %p.text-right
10
+ - resource.member_post_actions.each do |action|
11
+ - if EffectiveResources.authorized?(controller, action.to_sym, @resource)
12
+ - if resource.action_post_path(action, check: true).present?
13
+ = link_to action.titleize, send(resource.action_post_path(action), @resource), class: 'btn btn-primary',
14
+ data: { confirm: "Really #{action} #{@resource}?", method: :post }
14
15
 
15
- - if EffectiveResources.authorized?(controller, :destroy, @resource)
16
- - if resource.destroy_path(check: true).present?
17
- = link_to 'Delete', send(resource.destroy_path, @resource), class: 'btn btn-danger',
18
- data: { confirm: "Really delete #{@resource}?", method: :delete }
16
+ - if EffectiveResources.authorized?(controller, :destroy, @resource)
17
+ - if resource.destroy_path(check: true).present?
18
+ = link_to 'Delete', send(resource.destroy_path, @resource), class: 'btn btn-danger',
19
+ data: { confirm: "Really delete #{@resource}?", method: :delete }
19
20
 
20
- = render @resource
21
+ = render @resource
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '0.4.2'.freeze
2
+ VERSION = '0.4.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-09 00:00:00.000000000 Z
11
+ date: 2017-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails