Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ group :test do
gem 'capybara', '~> 2.2.1'
gem 'shoulda-matchers', '~> 2.6.0'
end

gem 'simple_form'
gem 'clearance'
12 changes: 12 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ GEM
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
arel (4.0.2)
bcrypt (3.1.7)
bourbon (3.1.8)
sass (>= 3.2.0)
thor
Expand All @@ -39,6 +40,10 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
clearance (1.3.0)
bcrypt
email_validator (~> 1.4)
rails (>= 3.1)
coderay (1.1.0)
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
Expand All @@ -50,6 +55,8 @@ GEM
columnize (0.3.6)
debugger-linecache (1.2.0)
diff-lcs (1.2.5)
email_validator (1.4.0)
activemodel
erubis (2.7.0)
execjs (2.0.2)
factory_girl (4.4.0)
Expand Down Expand Up @@ -122,6 +129,9 @@ GEM
sprockets-rails (~> 2.0)
shoulda-matchers (2.6.0)
activesupport (>= 3.0.0)
simple_form (3.0.1)
actionpack (>= 4.0.0, < 4.1)
activemodel (>= 4.0.0, < 4.1)
slop (3.5.0)
sprockets (2.11.0)
hike (~> 1.2)
Expand Down Expand Up @@ -151,6 +161,7 @@ PLATFORMS
DEPENDENCIES
bourbon (~> 3.1.8)
capybara (~> 2.2.1)
clearance
coffee-rails (~> 4.0.0)
factory_girl_rails (~> 4.4.1)
jquery-rails
Expand All @@ -162,4 +173,5 @@ DEPENDENCIES
rspec-rails (~> 2.14.2)
sass-rails (~> 4.0.3)
shoulda-matchers (~> 2.6.0)
simple_form
uglifier (>= 1.3.0)
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class ApplicationController < ActionController::Base
include Clearance::Controller
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class PagesController < ApplicationController

def index
end

end
56 changes: 56 additions & 0 deletions app/controllers/students_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
class StudentsController < ApplicationController
def index
@students = Student.all
end

def new
@student = Student.new
end

def create
@student = Student.new student_params

if @student.save
flash[:notice] = "Student Successfully Created."

redirect_to @student
else
render "new"
end
end

def show
@student = Student.find params[:id]
end

def edit
@student = Student.find params[:id]
end

def update
@student = Student.find params[:id]
if @student.update_attributes student_params
flash[:notice] = "Student Successfully Updated."
redirect_to @student
else
render "edit"
end
end

def destroy
@student = Student.find params[:id]

if @student.destroy
flash[:notice] = "Student Successfully Destroyed."
redirect_to students_path
else
render @student
end
end

private

def student_params
params.require(:student).permit(:name, :teacher_id)
end
end
9 changes: 9 additions & 0 deletions app/controllers/teachers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class TeachersController < ApplicationController
def index
@teachers = Teacher.all
end

def new
@student = Student.new
end
end
5 changes: 5 additions & 0 deletions app/models/student.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Student < ActiveRecord::Base
validates_presence_of :name

belongs_to :teacher
end
4 changes: 4 additions & 0 deletions app/models/teacher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Teacher < ActiveRecord::Base
validates_presence_of :name
has_many :students
end
3 changes: 3 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class User < ActiveRecord::Base
include Clearance::User
end
23 changes: 23 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,33 @@
<%= csrf_meta_tags %>
</head>
<body>


<div class="container">

<div class="login">
<% if signed_in? %>
Welcome <%= current_user.email %>
<%= link_to 'Sign out', sign_out_path, :method => :delete %>
<% else %>
<%= link_to 'Sign in', sign_in_path %>
<br />
<%= link_to 'Sign up', sign_up_path %>
<% end %>

<div id="flash">
<% flash.each do |key, value| %>
<div class="flash <%= key %>"><%= value %></div>
<% end %>
</div>

</div>


<%= render "shared/flash" %>

<%= yield %>
</div>

</body>
</html>
4 changes: 4 additions & 0 deletions app/views/pages/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<h1> Welcome to the Readathon2 web app</h1>

<%= link_to "Students", students_path %>
<%= link_to "Teachers", teachers_path %>
6 changes: 6 additions & 0 deletions app/views/students/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<%= simple_form_for @student do |f| %>
<%= f.input :name %>
<%= f.input :teacher_id, collection: Teacher.all %>

<%= f.submit %>
<% end %>
1 change: 1 addition & 0 deletions app/views/students/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render partial: "form" %>
9 changes: 9 additions & 0 deletions app/views/students/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h1> Students</h1>
<%= link_to "Add Student", new_student_path %>
<br /><br />

<% @students.each do |student| %>
<div class="student">
<%= link_to student.name, student %>
</div>
<% end %>
1 change: 1 addition & 0 deletions app/views/students/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render partial: "form" %>
7 changes: 7 additions & 0 deletions app/views/students/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<%= link_to "Back to student list", students_path %>

<h1><%= @student.name %></h1>
<h2><%= @student.teacher.name %></h2>

<%= link_to "Edit", edit_student_path %>
<%= link_to "Delete", @student, method: :delete, data:{confirm: "Are you sure?"} %>
9 changes: 9 additions & 0 deletions app/views/teachers/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h1> Teachers</h1>
<%= link_to "Add Teacher", new_teacher_path %>
<br /><br />

<% @teachers.each do |teacher| %>
<div class="teacher">
<%= link_to teacher.name, teacher %>
</div>
<% end %>
3 changes: 3 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true

# for clearance generated urls
config.action_mailer.default_url_options = { :host => 'http://devbox-78291.usw1.nitrousbox.com/' }
end
5 changes: 5 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@

# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr

# for clearance generated urls
config.action_mailer.default_url_options = { :host => 'http://devbox-78291.usw1.nitrousbox.com/' }

config.action_controller.action_on_unpermitted_parameters = :raise
end
3 changes: 3 additions & 0 deletions config/initializers/clearance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Clearance.configure do |config|
config.mailer_sender = 'reply@example.com'
end
59 changes: 4 additions & 55 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,56 +1,5 @@
Readathon2::Application.routes.draw do
# 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 'welcome#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

# 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
end
root 'pages#index'
resources :students
resources :teachers, only: [:index, :new, :show]
end
9 changes: 9 additions & 0 deletions db/migrate/20140415012144_create_students.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateStudents < ActiveRecord::Migration
def change
create_table :students do |t|
t.string :name

t.timestamps
end
end
end
18 changes: 18 additions & 0 deletions db/migrate/20140429000650_create_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.timestamps null: false
t.string :email, null: false
t.string :encrypted_password, limit: 128, null: false
t.string :confirmation_token, limit: 128
t.string :remember_token, limit: 128, null: false
end

add_index :users, :email
add_index :users, :remember_token
end

def self.down
drop_table :users
end
end
9 changes: 9 additions & 0 deletions db/migrate/20140429010121_create_teachers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateTeachers < ActiveRecord::Migration
def change
create_table :teachers do |t|
t.string :name, null: false

t.timestamps
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20140429011037_add_teacher_id_to_student.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddTeacherIdToStudent < ActiveRecord::Migration
def change
add_reference :students, :teacher, index: true
end
end
Loading