-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #315 from alaashafaee/C3_Mimi_212_edit_helping_tes…
…t_4.13 Pull Request: C3_Mimi_212_edit_helping_test_4.13
- Loading branch information
Showing
4 changed files
with
86 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters