File tree Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -7,8 +7,28 @@ def index
77 @event_groups = @event . event_groups
88 end
99
10+ # An action to regenerate
11+ # -> a controller method
12+ # -> button (to call the action)
13+ # -> a route
14+ # -> isolate generate behaviour in its own method
15+
1016 def generate
17+ fill_groups
18+ @event_groups = @event . event_groups
19+ redirect_to admin_event_groups_path ( @event ) , notice : "Groups successfully generated"
20+ end
1121
22+ def regenerate
23+ @event_groups = @event . event_groups
24+ @event_groups . destroy_all
25+ fill_groups
26+ redirect_to admin_event_groups_path ( @event ) , notice : "Groups successfully regenerated"
27+ end
28+
29+ private
30+
31+ def fill_groups
1232 # create a group for each pair of coaches
1333 @coaches = @event . coach_applications . approved . to_a
1434 @coaches . each_slice ( 2 ) . with_index do |group , index |
@@ -26,14 +46,8 @@ def generate
2646 event_group . applications << attendee_group unless attendee_group . empty?
2747 end
2848 end
29-
30- @event_groups = @event . event_groups
31-
32- redirect_to admin_event_groups_path ( @event ) , notice : "Groups successfully generated"
3349 end
3450
35- private
36-
3751 def find_event
3852 @event = Event . find ( params [ :event_id ] )
3953 end
Original file line number Diff line number Diff line change 11<% if @event.has_groups? %>
22
3+ <%= button_to "Regenerate groups", regenerate_admin_event_groups_path(@event), method: :post %>
34 <% @event_groups.each do |event_group| %>
45 <h2 > <%= event_group . name %> </ h2 >
56 < table >
Original file line number Diff line number Diff line change 4949 resources :groups , only : [ :index ] do
5050 collection do
5151 post :generate
52+ post :regenerate
5253 end
5354 end
5455 put :complete
You can’t perform that action at this time.
0 commit comments