Skip to content

Commit

Permalink
Issue alaashafaee#210 Adding helping hints
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed Fadel authored and Mohamed Fadel committed Apr 22, 2014
1 parent c42e0c0 commit 43968f6
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tutor/app/controllers/hints_controller.rb
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
21 changes: 21 additions & 0 deletions tutor/app/views/hints/new.html.erb
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 %>

0 comments on commit 43968f6

Please sign in to comment.