Skip to content

Commit d54f278

Browse files
committed
Create controller concern for move action
1 parent f9e401b commit d54f278

File tree

1 file changed

+31
-0
lines changed
  • admin/app/controllers/concerns/solidus_admin

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# frozen_string_literal: true
2+
3+
module SolidusAdmin::Moveable
4+
extend ActiveSupport::Concern
5+
6+
included do
7+
before_action :load_moveable, only: [:move]
8+
end
9+
10+
def move
11+
@moveable.insert_at(params.require(:position).to_i)
12+
13+
respond_to do |format|
14+
format.js { head :no_content }
15+
end
16+
end
17+
18+
private
19+
20+
def load_moveable
21+
@moveable = moveable_class.find(params.require(:id))
22+
authorize! action_name, @moveable
23+
end
24+
25+
def moveable_class
26+
"Spree::#{self.class.name.demodulize.remove('Controller').singularize}".constantize
27+
rescue NameError
28+
raise NameError,
29+
"could not infer model class from #{self.class.name}. Please override `moveable_class` to specify it explicitly."
30+
end
31+
end

0 commit comments

Comments
 (0)