diff --git a/tutor/app/controllers/model_answers_controller.rb b/tutor/app/controllers/model_answers_controller.rb index ae8c8b6e..c2a96a71 100644 --- a/tutor/app/controllers/model_answers_controller.rb +++ b/tutor/app/controllers/model_answers_controller.rb @@ -21,10 +21,12 @@ def create @answer = ModelAnswer.new(post_params) if @answer.save flash[:notice] = "Your Answer is now added" - redirect_to :back + redirect_to :controller => 'problems', :action => 'edit' , :id => @answer.problem_id + else flash[:notice] = "Your Answer can not be added " - redirect_to :back + redirect_to :controller => 'problems', :action => 'edit' , :id => @answer.problem_id + end end @@ -56,6 +58,6 @@ def index # Author: Nadine Adel private def post_params - params.require(:model_answer).permit(:answer) + params.require(:model_answer).permit(:answer, :problem_id) end end \ No newline at end of file diff --git a/tutor/app/controllers/problems_controller.rb b/tutor/app/controllers/problems_controller.rb index 87756df6..041c16b9 100644 --- a/tutor/app/controllers/problems_controller.rb +++ b/tutor/app/controllers/problems_controller.rb @@ -50,6 +50,8 @@ def permitCreate # Author: Abdullrahman Elhusseny def edit @problem = Problem.find_by_id(params[:id]) + @test_cases = @problem.test_cases + @answers = @problem.model_answers end def new if lecturer_signed_in? diff --git a/tutor/app/controllers/test_cases_controller.rb b/tutor/app/controllers/test_cases_controller.rb index 6293d262..b0b2ceef 100644 --- a/tutor/app/controllers/test_cases_controller.rb +++ b/tutor/app/controllers/test_cases_controller.rb @@ -25,10 +25,10 @@ def create @test_case = TestCase.new(post_params) if @test_case.save flash[:notice] = "Post created successfully" - redirect_to :back + redirect_to :controller => 'problems', :action => 'edit' , :id => @test_case.problem_id else flash[:notice] = "Can't add test case!" - redirect_to :back + redirect_to :controller => 'problems', :action => 'edit' , :id => @test_case.problem_id end end # [Add test case-story 4.8] @@ -38,6 +38,6 @@ def create # Author: Lin private def post_params - params.require(:test_case).permit(:input, :output) + params.require(:test_case).permit(:input, :output, :problem_id) end end diff --git a/tutor/app/views/model_answers/new.html.erb b/tutor/app/views/model_answers/_new.html.erb similarity index 86% rename from tutor/app/views/model_answers/new.html.erb rename to tutor/app/views/model_answers/_new.html.erb index 1bd0fb69..23d8626b 100644 --- a/tutor/app/views/model_answers/new.html.erb +++ b/tutor/app/views/model_answers/_new.html.erb @@ -12,6 +12,7 @@

Please Insert your model answer

<%= f.text_area :answer %> + <%= f.hidden_field :problem_id, value: params[:id] %>

<%= f.submit %> diff --git a/tutor/app/views/problems/edit.html.erb b/tutor/app/views/problems/edit.html.erb index 191bd913..3ad20f58 100644 --- a/tutor/app/views/problems/edit.html.erb +++ b/tutor/app/views/problems/edit.html.erb @@ -2,4 +2,7 @@ a header to view the problem title of the instance variable @problem and a paragraph to view the problem description of the instance variable @problem -->

<%= @problem.title %>

-

<%= @problem.description %>

\ No newline at end of file +

<%= @problem.description %>

+ +<%= render partial: "test_cases/index"%> +<%= render partial: "model_answers/new"%> \ No newline at end of file diff --git a/tutor/app/views/test_cases/_form.html.erb b/tutor/app/views/test_cases/_form.html.erb index 941c3b5d..771930ff 100644 --- a/tutor/app/views/test_cases/_form.html.erb +++ b/tutor/app/views/test_cases/_form.html.erb @@ -6,6 +6,7 @@ <%= f.text_field :input %> <%= f.label :Output %> <%= f.text_field :output %> + <%= f.hidden_field :problem_id, value: params[:id] %>

<%= f.submit 'Add test case' %> diff --git a/tutor/app/views/test_cases/index.html.erb b/tutor/app/views/test_cases/_index.html.erb similarity index 86% rename from tutor/app/views/test_cases/index.html.erb rename to tutor/app/views/test_cases/_index.html.erb index a92bc9ba..038f75fa 100644 --- a/tutor/app/views/test_cases/index.html.erb +++ b/tutor/app/views/test_cases/_index.html.erb @@ -7,4 +7,4 @@ <% end %> -<%= render "form"%> \ No newline at end of file +<%= render partial: "test_cases/form"%>