Skip to content

Commit

Permalink
Issue #208 Linking to adding test cases & answers
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdullRahman ElHusseini committed Apr 14, 2014
1 parent ff570d8 commit b9cd4e9
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 8 deletions.
8 changes: 5 additions & 3 deletions tutor/app/controllers/model_answers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions tutor/app/controllers/problems_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
6 changes: 3 additions & 3 deletions tutor/app/controllers/test_cases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<p>
<h2>Please Insert your model answer</h2>
<%= f.text_area :answer %>
<%= f.hidden_field :problem_id, value: params[:id] %>
</p>
<p>
<%= f.submit %>
Expand Down
5 changes: 4 additions & 1 deletion tutor/app/views/problems/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
<h2 align ="center"><%= @problem.title %></h2>
<p><%= @problem.description %></p>
<p><%= @problem.description %></p>

<%= render partial: "test_cases/index"%>
<%= render partial: "model_answers/new"%>
1 change: 1 addition & 0 deletions tutor/app/views/test_cases/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<%= f.text_field :input %>
<%= f.label :Output %>
<%= f.text_field :output %>
<%= f.hidden_field :problem_id, value: params[:id] %>
</p>
<p >
<%= f.submit 'Add test case' %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
</tr>
<% end %>
</table>
<%= render "form"%>
<%= render partial: "test_cases/form"%>

0 comments on commit b9cd4e9

Please sign in to comment.