Skip to content

Commit

Permalink
Merge pull request #315 from alaashafaee/C3_Mimi_212_edit_helping_tes…
Browse files Browse the repository at this point in the history
…t_4.13

Pull Request: C3_Mimi_212_edit_helping_test_4.13
  • Loading branch information
Mamdou7 committed Apr 25, 2014
2 parents 2aedaf7 + 9c9f681 commit ab29d53
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 6 deletions.
58 changes: 58 additions & 0 deletions tutor/app/controllers/hints_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
class HintsController < ApplicationController

# [Edit helping hints - Story 4.13 ]
# This action creates the form and retrives the data of the selected problem
# to be being edited
# Parameters:
# ID of the hint
# Returns: none
# Author: Mimi
def edit
if current_lecturer or current_teaching_assistant
@new_tip = Hint.find_by_id(params[:id])
else
render "public/500.html"
end
end

# [Edit helping hints - Story 4.13 ]
# This action takes the passed parameters from
# the creation form, edits a Hint record
# which assigned to the respective problem. If the
# edit fails the user is redirected to the form
# with a "Failed" message.
# Parameters:
# hint_params[]: A list that has all fields entered by the user to in the
# edit_hint form
# Returns:
# flash[:notice]: A message indicating the success or failure of the edit
# Author: Mimi
def update
@new_tip = Hint.find_by_id(hint_params[:id])
@new_tip.message = hint_params[:message]
@new_tip.submission_counter = hint_params[:submission_counter]
@model_answer = @new_tip.model_answer_id
bool = @new_tip.save
if bool == true
flash[:notice] = "Hint successfully edited"
redirect_to :controller => 'model_answers', :action => 'edit', :id => @model_answer
else
if @new_tip.errors.any?
flash[:notice] = @new_tip.errors.full_messages.first
end
redirect_to :back
end
end

# [Edit helping hints - Story 4.13 ]
# Description:
# take the parameters from the from
# Parameters: none
# Returns:
# Hash of paramas
# Author: Mimi
private
def hint_params
params.require(:hint).permit(:message, :submission_counter, :id)
end
end
10 changes: 4 additions & 6 deletions tutor/app/models/hint.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
class Hint < ActiveRecord::Base

#Validations
validates :message, presence: true
validates :submission_counter, presence: true, numericality: {
only_integer: true, greater_than_or_equal_to: 0, message: "is not valid"}

#Relations
belongs_to :model_answer
belongs_to :owner, polymorphic: true

#Scoops

#Methods

end
23 changes: 23 additions & 0 deletions tutor/app/views/hints/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<% if flash[:notice] -%>
<div class="alert alert-warning", style="width:180px;display:inline">
<%= flash[:notice] %>
</div>
<% end %>
<br/>
<br/>
<br/>
<!-- Rendering the form fields -->
<%= form_for @new_tip, url:{:controller => "hints", action:"update"} do |f| %>
<%= f.hidden_field :id, value: params[:id] %>
<p>
<%= f.label "Hint description" %><br>
<%= f.text_area :message, :cols => "100", :rows => "8", autofocus:true, class:"form-control", style:"width:300px", value:Hint.find_by_id(params[:id]).message %>
</p>
<p>
<%= f.label :"The number of wrong submissions that hint appears after" %><br>
<%= f.text_area :submission_counter, :rows => "1", class:"form-control", style: "width:300px", value:Hint.find_by_id(params[:id]).submission_counter %>
</p>
<p>
<%= f.submit"Save", class:"btn btn-success"%>
</p>
<% end %>
1 change: 1 addition & 0 deletions tutor/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
resources :model_answers
resources :solutions
resources :topics
resources :hints
resources :lecturers
resources :teaching_assistants
resources :students
Expand Down

0 comments on commit ab29d53

Please sign in to comment.