forked from alaashafaee/Coolsoft-14
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue alaashafaee#210 Adding helping hints
- Loading branch information
Mohamed Fadel
authored and
Mohamed Fadel
committed
Apr 22, 2014
1 parent
c42e0c0
commit 43968f6
Showing
2 changed files
with
65 additions
and
0 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,44 @@ | ||
class HintsController < ApplicationController | ||
|
||
@@answer_id = nil | ||
|
||
# [Adding Helping Hints - 4.12] | ||
# Creates a new record to Hint Table | ||
# Parameters: | ||
# owner_id: ID of the hint owner | ||
# owner type: type of hint owner | ||
# category: states whether it is a hint or tip | ||
# Returns: Redirects to edit page on success, refreshes on failure | ||
# Author: Mohamed Fadel | ||
def create | ||
p = Hint.new(permitCreate) | ||
if lecturer_signed_in? | ||
p.owner_id = current_lecturer.id | ||
p.owner_type = "lecturer" | ||
p.category = false | ||
p.model_answer_id = @@answer_id | ||
else | ||
p.owner_id = current_teaching_assistant.id | ||
p.owner_type = "teaching_assistant" | ||
p.category = false | ||
p.model_answer_id = @@answer_id | ||
end | ||
|
||
if p.save | ||
redirect_to :controller => 'model_answers', :action => 'edit', :id => @@answer_id | ||
else | ||
flash.keep[:notice] = "Hint is missing paramaters" | ||
redirect_to :back | ||
end | ||
end | ||
|
||
# [Adding Helping Hints - 4.12] | ||
# Passes the input of the form as paramaters for create action to use it | ||
# Parameters: | ||
# submission_counter: hint's submission counter | ||
# message: hint's message | ||
# Returns: params to create action | ||
# Author: Mohamed Fadel | ||
def permitCreate | ||
params.require(:Hint).permit(:submission_counter, :message) | ||
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,21 @@ | ||
<h1 align ="center">Add a Hint</h1> | ||
<br> | ||
<!--A form that takes the input for the model Hint and calls the action create | ||
through two text fields :title and description --> | ||
<%= form_for :Hint, url: {action: "create"} do |p| %> | ||
<p> | ||
<%= p.label :submission_counter %><br> | ||
<%= p.text_field :submission_counter %> | ||
</p> | ||
<p> | ||
<%= p.label :message %><br> | ||
<%= p.text_area :message , :cols => "50", :rows => "10" %> | ||
</p> | ||
<p> | ||
<%= p.submit %> | ||
</p> | ||
<% end %> | ||
<!-- A division for the flash message output to view the action's output --> | ||
<% if flash[:notice] %> | ||
<div class="notice"><%= flash[:notice] %></div> | ||
<% end %> |