effective_resources 0.8.9 → 0.8.10

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: e5e1a1245e78f09a87b8d00b5ed756123361f6a2
4
- data.tar.gz: 4be2ae1bf73c6774743c3439e2ab1bde1c30b7a4
3
+ metadata.gz: 7c8bdc84abf94942e54c5007aedf0d5ed6258473
4
+ data.tar.gz: b4cee9fb014e4a40ba1cdbba3d1caee1e45cf084
5
5
  SHA512:
6
- metadata.gz: fc0fbf0354dfef9185ce31024b0055b2be3adff96c69d91de1bc512f0e4bd21063d052d883e5bf0bd8678cbba93641c34df89e05867da7c04d78f59bc12ac225
7
- data.tar.gz: 9c5faa4057cbfc2e7118df702cffdf1a81aa8485d22f5210b72505b56be92b75d228f84735ee3612a584dcccc121d2f28bf55423069eaafd8208339b7039a3f2
6
+ metadata.gz: eefe5e914263f9fe5da1c41362d1c67b7289db996a19b86b5cc51edb67848ab07cdfcfa3ce049c7a38d3b85b2fcfd2901c9d6a7eba51aa31de8e0141ab975f56
7
+ data.tar.gz: 0b37485ef2faca4106f55b81cac1fb8966854c75f9fa8faf31ca1ca8d05d2e8f7b3ba3634ee34ed3a3c2403ea33f5c98475c27759138def3dd7cf7001540d8bd
@@ -324,29 +324,52 @@ module Effective
324
324
  end
325
325
  end
326
326
 
327
- # No attributes are assigned or saved. We purely call action! on the resource.
328
327
  def member_post_action(action)
329
328
  raise 'expected post, patch or put http action' unless (request.post? || request.patch? || request.put?)
330
329
 
331
- if save_resource(resource, action)
332
- flash[:success] ||= resource_flash(:success, resource, action)
333
- redirect_to(referer_redirect_path || resource_redirect_path)
334
- else
335
- flash.now[:danger] ||= resource_flash(:danger, resource, action)
336
-
337
- if resource_edit_path && (referer_redirect_path || '').end_with?(resource_edit_path)
338
- @page_title ||= "Edit #{resource}"
339
- render :edit
340
- elsif resource_new_path && (referer_redirect_path || '').end_with?(resource_new_path)
341
- @page_title ||= "New #{resource_name.titleize}"
342
- render :new
343
- elsif resource_show_path && (referer_redirect_path || '').end_with?(resource_show_path)
344
- @page_title ||= resource_name.titleize
345
- render :show
330
+ # TODO: This is a recent change. Used to not assign attributes. Is this breaking?
331
+ valid_params = (send(resource_params_method_name) rescue {})
332
+ resource.assign_attributes(valid_params)
333
+
334
+ respond_to do |format|
335
+ if save_resource(resource, action)
336
+ format.html do
337
+ flash[:success] ||= resource_flash(:success, resource, action)
338
+ redirect_to(resource_redirect_path)
339
+ end
340
+
341
+ format.js do
342
+ if specific_redirect_path?(action)
343
+ flash[:success] ||= resource_flash(:success, resource, action)
344
+ redirect_to(resource_redirect_path)
345
+ else
346
+ flash.now[:success] ||= resource_flash(:success, resource, action)
347
+ reload_resource
348
+ # action.js.erb
349
+ end
350
+ end
346
351
  else
347
- @page_title ||= resource.to_s
348
- flash[:danger] = flash.now[:danger]
349
- redirect_to(referer_redirect_path || resource_redirect_path)
352
+ flash.delete(:success)
353
+ flash.now[:danger] ||= resource_flash(:danger, resource, action)
354
+
355
+ format.html do
356
+ if resource_edit_path && (referer_redirect_path || '').end_with?(resource_edit_path)
357
+ @page_title ||= "Edit #{resource}"
358
+ render :edit
359
+ elsif resource_new_path && (referer_redirect_path || '').end_with?(resource_new_path)
360
+ @page_title ||= "New #{resource_name.titleize}"
361
+ render :new
362
+ elsif resource_show_path && (referer_redirect_path || '').end_with?(resource_show_path)
363
+ @page_title ||= resource_name.titleize
364
+ render :show
365
+ else
366
+ @page_title ||= resource.to_s
367
+ flash[:danger] = flash.now[:danger]
368
+ redirect_to(referer_redirect_path || resource_redirect_path)
369
+ end
370
+ end
371
+
372
+ format.js {} # action.js.erb
350
373
  end
351
374
  end
352
375
  end
@@ -544,8 +567,15 @@ module Effective
544
567
  { action: :save }
545
568
  end
546
569
 
547
- def specific_redirect_path?
548
- (commit_action[:redirect].respond_to?(:call) ? instance_exec(&commit_action[:redirect]) : commit_action[:redirect]).present?
570
+ def submit_action(action)
571
+ self.class.submits[action.to_s] ||
572
+ self.class.submits.find { |_, v| v[:action] == action }&.last ||
573
+ { action: action }
574
+ end
575
+
576
+ def specific_redirect_path?(action = nil)
577
+ submit = (action.nil? ? commit_action : submit_action(action))
578
+ (submit[:redirect].respond_to?(:call) ? instance_exec(&submit[:redirect]) : submit[:redirect]).present?
549
579
  end
550
580
 
551
581
  # Returns an ActiveRecord relation based on the computed value of `resource_scope` dsl method
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '0.8.9'.freeze
2
+ VERSION = '0.8.10'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.9
4
+ version: 0.8.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect