Skip to content

Commit c12b80c

Browse files
committed
duplicate an exercise #30
1 parent 01b69b0 commit c12b80c

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

app/controllers/exercises_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ def new
2727
@exercise.descriptions << Description.new
2828
end
2929

30+
def duplicate
31+
@exercise = Exercise.new(Exercise.find(params[:id]).attributes)
32+
render 'new'
33+
end
34+
3035
# GET /exercises/1/edit
3136
def edit
3237
end

app/models/ability.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def initialize(user)
88
elsif user.role == 'teacher'
99
can :show, Exercise
1010
can :create, Exercise
11+
can :duplicate, Exercise
1112
can :read, Exercise
1213
can :edit, Exercise do |exercise|
1314
exercise.user == user

app/views/home/_exercises.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
<div class="btn-group-vertical pull-right" role="group" aria-label="...">
3030
<%= link_to 'Select', exercise_path(exercise), class:'btn btn-default' %>
3131
<%= link_to 'Show Comments', exercise_comments_path(exercise), class:'btn btn-default' %>
32+
<% if can? :create, exercise %>
33+
<%= link_to 'Duplicate', duplicate_exercise_path(exercise), class:'btn btn-default' %>
34+
<% end %>
3235
<% if can? :edit, exercise %>
3336
<%= link_to 'Edit', edit_exercise_path(exercise), class:'btn btn-default' %>
3437
<%= link_to 'Delete', exercise_path(exercise), class:'btn btn-default', method: :delete, data: { confirm: 'Are you sure?' } %>

config/routes.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
get 'comments/comments_all'
1818

19-
get 'exercises/exercises_all'
19+
get 'exercises/:id/duplicate', to: 'exercises#duplicate', as: 'duplicate_exercise'
2020

2121
resources :labels
2222
resources :label_categories
@@ -35,6 +35,9 @@
3535
end
3636
end
3737

38+
get 'exercises/exercises_all'
39+
40+
3841

3942

4043
# The priority is based upon order of creation: first created -> highest priority.

0 commit comments

Comments
 (0)