Skip to content

Commit

Permalink
Merge pull request #202 from alaashafaee/C4_Husseny_201_add_problem_4.4
Browse files Browse the repository at this point in the history
Issue #201 Add problems by tas
  • Loading branch information
husseny committed Apr 13, 2014
2 parents 4b90d70 + 9de191f commit e359769
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 2 deletions.
3 changes: 3 additions & 0 deletions tutor/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ gem 'foreman'

# Use debugger
# gem 'debugger', group: [:development, :test]

# Use composite primary keys in models
gem 'composite_primary_keys', '~> 6.0.1'
3 changes: 3 additions & 0 deletions tutor/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.7.0)
composite_primary_keys (6.0.1)
activerecord (>= 4.0.0)
dotenv (0.10.0)
erubis (2.7.0)
execjs (2.0.2)
Expand Down Expand Up @@ -120,6 +122,7 @@ PLATFORMS

DEPENDENCIES
coffee-rails (~> 4.0.0)
composite_primary_keys (~> 6.0.1)
foreman
jbuilder (~> 1.2)
jquery-rails (~> 3.1.0)
Expand Down
3 changes: 3 additions & 0 deletions tutor/app/assets/javascripts/problems_by_tas.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions tutor/app/assets/stylesheets/problems_by_tas.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the problems_by_tas controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
39 changes: 39 additions & 0 deletions tutor/app/controllers/problems_by_tas_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class ProblemsByTasController < ApplicationController
# [Add Problem - 4.4]
# Creates a new record to Problem Table
# Parameters:
# title: problem's title through permitCreate action
# description: problem's description through permitCreate action
# Returns: Redirects to edit page on success, refreshes on failure
# Author: Abdullrahman Elhusseny
def create
p = Problem.new(permitCreate)
if p.save
redirect_to :action => "edit", :id => p.id
else
flash.keep[:notice] = "Problem are missing paramaters"
redirect_to :back
end
end
# [Add Problem - 4.4]
# Passes the input of the form as paramaters for create action to use it
# Parameters:
# title: problem's title
# description: problem's description
# Returns: params to create action
# Author: Abdullrahman Elhusseny
def permitCreate
params.require(:Problem).permit(:title , :description)
end
# [Edit Problem - 4.5]
# Shows the problem's title and description (Further development is in Sprint 1)
# Parameters:
# id: The id of the problem to be edited or newly created
# Returns: Redirects to edit page on success, refreshes on failure
# Author: Abdullrahman Elhusseny
def edit
@problem = Problem.find_by_id(params[:id])
end
def new
end
end
2 changes: 2 additions & 0 deletions tutor/app/helpers/problems_by_tas_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ProblemsByTasHelper
end
3 changes: 2 additions & 1 deletion tutor/app/models/problem.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class Problem < ActiveRecord::Base

#Validations

validates_presence_of :title
validates_presence_of :description
#Relations
belongs_to :owner, class_name: 'Staff', foreign_key: :staff_id
belongs_to :track
Expand Down
5 changes: 5 additions & 0 deletions tutor/app/views/problems_by_tas/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- The html web page consists of two tags
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>
24 changes: 24 additions & 0 deletions tutor/app/views/problems_by_tas/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<h1 align ="center">Edit Problem Page</h1>

<br>
<!--A form that takes the input for the model Problem and calls the action create
through two text fields :title and description -->
<%= form_for :Problem, url: {action: "create"} do |p| %>
<p>
<%= p.label :title %><br>
<%= p.text_field :title %>
</p>

<p>
<%= p.label :description %><br>
<%= p.text_area :description , :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 %>
60 changes: 59 additions & 1 deletion tutor/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,61 @@
Tutor::Application.routes.draw do
resources :tracks do
post 'getProblems' , on: :member
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".

# You can have the root of your site routed with "root"
root 'site#index'

# Example of regular route:
# get 'products/:id' => 'catalog#view'

# Example of named route that can be invoked with purchase_url(id: product.id)
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase

# Example resource route (maps HTTP verbs to controller actions automatically):
# resources :products
resources :problems_by_tas
# Example resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end

# Example resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end

# Example resource route with more complex sub-resources:
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', on: :collection
# end
# end

# Example resource route with concerns:
# concern :toggleable do
# post 'toggle'
# end
# resources :posts, concerns: :toggleable
# resources :photos, concerns: :toggleable

# Example resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
=======
resources :tracks do
post 'getProblems' , on: :member
end
Expand Down Expand Up @@ -56,5 +113,6 @@
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
>>>>>>> 4b90d70c448b33cb228b1c944d8c98e00b529012
end


0 comments on commit e359769

Please sign in to comment.