Skip to content

Commit

Permalink
Fixing conflicts #211
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed Fadel authored and Mohamed Fadel committed Apr 25, 2014
2 parents 78ea8f6 + ba48938 commit 953b58d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tutor/app/controllers/model_answers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ def create
end
end

# [Remove Answer - Story 4.17]
# This action takes the model answer id, and check if it is not the last model answer in the
# problem and remove it from the database and then redirects the user to the edit problem
# page of the problem that had the answer with a "Model Answer successfully Deleted" message.
# Parameters:
# params[:id]: The current model answer's id
# Returns:
# flash[:notice]: A message indicating the success of the deletion
# Author: Ahmed Atef
def destroy
@model_answer = ModelAnswer.find_by_id(params[:id])
@current = Problem.find_by_id(@model_answer.problem_id)
if @current.model_answers.count == 1
flash[:notice] = "Cannot delete problem's last model answer"
redirect_to :back and return
elsif @model_answer.destroy
flash[:notice] = "Answer successfully Deleted"
redirect_to(:controller => 'problems', :action => 'edit', :id => @current.id)
end
end

# [Edit answer story 4.7]
# Answer that has been created before is edited
# Parameters:
Expand Down Expand Up @@ -83,7 +104,7 @@ def update

end
end

# [Add answer story 4.6]
# It shows answer that was entered before.
# Parameters:
Expand Down
4 changes: 4 additions & 0 deletions tutor/app/views/model_answers/_index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
{controller: :hints, action: :destroy, id: hint1.id},
:method => :delete, class: 'btn btn-primary btn-xs' %></td>
<td><a href="#" class="btn btn-danger btn-xs">Delete</a></td>
<td><%= button_to "Delete", {:controller => 'model_answers',:action => 'destroy',
:id => answer1.id}, method: :delete, class: 'btn btn-primary',
:confirm => "Are you sure you want to delete
this Answer ?" %></td>
</tr>
<% end %>
</tbody>
Expand Down

0 comments on commit 953b58d

Please sign in to comment.