diff --git a/Gemfile b/Gemfile index 5b632a2..fb861ef 100644 --- a/Gemfile +++ b/Gemfile @@ -37,3 +37,6 @@ group :test do gem 'capybara', '~> 2.2.1' gem 'shoulda-matchers', '~> 2.6.0' end + +gem 'simple_form' +gem 'clearance' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 716a7bc..da695d7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 @@ -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) @@ -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) @@ -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) @@ -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 @@ -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) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d83690e..1bf0ba0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb new file mode 100644 index 0000000..0472131 --- /dev/null +++ b/app/controllers/pages_controller.rb @@ -0,0 +1,6 @@ +class PagesController < ApplicationController + + def index + end + +end \ No newline at end of file diff --git a/app/controllers/students_controller.rb b/app/controllers/students_controller.rb new file mode 100644 index 0000000..b95e934 --- /dev/null +++ b/app/controllers/students_controller.rb @@ -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 \ No newline at end of file diff --git a/app/controllers/teachers_controller.rb b/app/controllers/teachers_controller.rb new file mode 100644 index 0000000..f8971b9 --- /dev/null +++ b/app/controllers/teachers_controller.rb @@ -0,0 +1,9 @@ +class TeachersController < ApplicationController + def index + @teachers = Teacher.all + end + + def new + @student = Student.new + end +end \ No newline at end of file diff --git a/app/models/student.rb b/app/models/student.rb new file mode 100644 index 0000000..e333ce4 --- /dev/null +++ b/app/models/student.rb @@ -0,0 +1,5 @@ +class Student < ActiveRecord::Base + validates_presence_of :name + + belongs_to :teacher +end diff --git a/app/models/teacher.rb b/app/models/teacher.rb new file mode 100644 index 0000000..3cca1c5 --- /dev/null +++ b/app/models/teacher.rb @@ -0,0 +1,4 @@ +class Teacher < ActiveRecord::Base + validates_presence_of :name + has_many :students +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..6d077a1 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,3 @@ +class User < ActiveRecord::Base + include Clearance::User +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index a70d187..7b1c280 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,10 +7,33 @@ <%= csrf_meta_tags %>
+ +