diff --git a/tutor/app/controllers/hints_controller.rb b/tutor/app/controllers/hints_controller.rb new file mode 100644 index 00000000..77cf8804 --- /dev/null +++ b/tutor/app/controllers/hints_controller.rb @@ -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 \ No newline at end of file diff --git a/tutor/app/views/hints/new.html.erb b/tutor/app/views/hints/new.html.erb new file mode 100644 index 00000000..684eb999 --- /dev/null +++ b/tutor/app/views/hints/new.html.erb @@ -0,0 +1,21 @@ +

Add a Hint

+
+ +<%= form_for :Hint, url: {action: "create"} do |p| %> +

+ <%= p.label :submission_counter %>
+ <%= p.text_field :submission_counter %> +

+

+ <%= p.label :message %>
+ <%= p.text_area :message , :cols => "50", :rows => "10" %> +

+

+ <%= p.submit %> +

+<% end %> + +<% if flash[:notice] %> +
<%= flash[:notice] %>
+<% end %> \ No newline at end of file