Skip to content

Commit 5966dc1

Browse files
author
Marcel Jankrift
committed
Merge pull request #32 from openHPI/30_duplicate_function
30 duplicate function
2 parents 01b69b0 + 9883c08 commit 5966dc1

File tree

6 files changed

+17
-5
lines changed

6 files changed

+17
-5
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/exercises/_test_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</div>
88
<div class="field">
99
<%= f.label :feedback_message %><br>
10-
<%= test.text_field :feedback_message %>
10+
<%= test.text_field :feedback_message, size:80 %>
1111
</div>
1212
<div class="field">
1313
<%= f.label :testing_framework %><br>

app/views/exercises/show.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
<dt><%= 'Visibility' %>:</dt>
1313
<dd><%= @exercise.public ? 'public' : 'private' %></dd>
1414
<dt><%= 'Created by' %>:</dt>
15-
<% if defined? @exercise.user %>
15+
<% if @exercise.user %>
1616
<% if @exercise.user.first_name.nil?%>
1717
<dd><%= "User#{@exercise.user.id}"%></dd>
1818
<% else %>
19-
<dd><%= @exercise.user.name %></dd>
19+
<dd><%= @exercise.user.name %></dd>
2020
<% end %>
2121
<% else %>
22-
<%= 'User undefined' %>
22+
<dd><%= 'User undefined' %></dd>
2323
<% end %>
2424
<dt><%= 'Created at' %>:</dt>
2525
<dd><%= @exercise.created_at %></dd>

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)