diff --git a/Gemfile b/Gemfile index 0447f70941..a4189730ec 100644 --- a/Gemfile +++ b/Gemfile @@ -4,9 +4,9 @@ source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.0.0' # Use sqlite3 as the database for Active Record -gem 'sqlite3' +gem 'sqlite3', '1.3.13' # Use Puma as the app server -gem 'puma', '~> 3.0' +gem 'puma', '4.2.1' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets @@ -30,6 +30,12 @@ gem 'jbuilder', '~> 2.5' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development +gem 'bootstrap-sass' + +gem 'devise' + +gem 'simple_form' + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platform: :mri diff --git a/Gemfile.lock b/Gemfile.lock index b69882a8dc..ecb8931950 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,175 +1,203 @@ GEM remote: https://rubygems.org/ specs: - actioncable (5.0.0) - actionpack (= 5.0.0) - nio4r (~> 1.2) + actioncable (5.0.7.2) + actionpack (= 5.0.7.2) + nio4r (>= 1.2, < 3.0) websocket-driver (~> 0.6.1) - actionmailer (5.0.0) - actionpack (= 5.0.0) - actionview (= 5.0.0) - activejob (= 5.0.0) + actionmailer (5.0.7.2) + actionpack (= 5.0.7.2) + actionview (= 5.0.7.2) + activejob (= 5.0.7.2) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.0.0) - actionview (= 5.0.0) - activesupport (= 5.0.0) + actionpack (5.0.7.2) + actionview (= 5.0.7.2) + activesupport (= 5.0.7.2) rack (~> 2.0) rack-test (~> 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.0.0) - activesupport (= 5.0.0) + actionview (5.0.7.2) + activesupport (= 5.0.7.2) builder (~> 3.1) erubis (~> 2.7.0) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - activejob (5.0.0) - activesupport (= 5.0.0) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (5.0.7.2) + activesupport (= 5.0.7.2) globalid (>= 0.3.6) - activemodel (5.0.0) - activesupport (= 5.0.0) - activerecord (5.0.0) - activemodel (= 5.0.0) - activesupport (= 5.0.0) + activemodel (5.0.7.2) + activesupport (= 5.0.7.2) + activerecord (5.0.7.2) + activemodel (= 5.0.7.2) + activesupport (= 5.0.7.2) arel (~> 7.0) - activesupport (5.0.0) + activesupport (5.0.7.2) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) + i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - arel (7.1.0) - builder (3.2.2) - byebug (9.0.5) - coffee-rails (4.2.1) + arel (7.1.4) + autoprefixer-rails (9.7.6) + execjs + bcrypt (3.1.13) + bindex (0.8.1) + bootstrap-sass (3.4.1) + autoprefixer-rails (>= 5.2.1) + sassc (>= 2.0.0) + builder (3.2.4) + byebug (11.1.3) + coffee-rails (4.2.2) coffee-script (>= 2.2.0) - railties (>= 4.0.0, < 5.2.x) + railties (>= 4.0.0) coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.10.0) - concurrent-ruby (1.0.2) - debug_inspector (0.0.2) + coffee-script-source (1.12.2) + concurrent-ruby (1.1.6) + crass (1.0.6) + devise (4.7.1) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 4.1.0) + responders + warden (~> 1.2.3) erubis (2.7.0) execjs (2.7.0) - ffi (1.9.14) - globalid (0.3.6) - activesupport (>= 4.1.0) - i18n (0.7.0) - jbuilder (2.5.0) - activesupport (>= 3.0.0, < 5.1) - multi_json (~> 1.2) - jquery-rails (4.1.1) + ffi (1.12.2) + globalid (0.4.2) + activesupport (>= 4.2.0) + i18n (1.8.2) + concurrent-ruby (~> 1.0) + jbuilder (2.10.0) + activesupport (>= 5.0.0) + jquery-rails (4.4.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - loofah (2.0.3) + loofah (2.5.0) + crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.6.4) - mime-types (>= 1.16, < 4) - method_source (0.8.2) - mime-types (3.1) - mime-types-data (~> 3.2015) - mime-types-data (3.2016.0521) - mini_portile2 (2.1.0) - minitest (5.9.0) - multi_json (1.12.1) - nio4r (1.2.1) - nokogiri (1.6.8) - mini_portile2 (~> 2.1.0) - pkg-config (~> 1.1.7) - pkg-config (1.1.7) - puma (3.5.2) - rack (2.0.1) + mail (2.7.1) + mini_mime (>= 0.1.1) + method_source (1.0.0) + mini_mime (1.0.2) + mini_portile2 (2.4.0) + minitest (5.14.0) + nio4r (2.5.2) + nokogiri (1.10.9) + mini_portile2 (~> 2.4.0) + orm_adapter (0.5.0) + puma (4.2.1) + nio4r (~> 2.0) + rack (2.2.2) rack-test (0.6.3) rack (>= 1.0) - rails (5.0.0) - actioncable (= 5.0.0) - actionmailer (= 5.0.0) - actionpack (= 5.0.0) - actionview (= 5.0.0) - activejob (= 5.0.0) - activemodel (= 5.0.0) - activerecord (= 5.0.0) - activesupport (= 5.0.0) - bundler (>= 1.3.0, < 2.0) - railties (= 5.0.0) + rails (5.0.7.2) + actioncable (= 5.0.7.2) + actionmailer (= 5.0.7.2) + actionpack (= 5.0.7.2) + actionview (= 5.0.7.2) + activejob (= 5.0.7.2) + activemodel (= 5.0.7.2) + activerecord (= 5.0.7.2) + activesupport (= 5.0.7.2) + bundler (>= 1.3.0) + railties (= 5.0.7.2) sprockets-rails (>= 2.0.0) - rails-dom-testing (2.0.1) - activesupport (>= 4.2.0, < 6.0) - nokogiri (~> 1.6.0) - rails-html-sanitizer (1.0.3) - loofah (~> 2.0) - railties (5.0.0) - actionpack (= 5.0.0) - activesupport (= 5.0.0) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.3.0) + loofah (~> 2.3) + railties (5.0.7.2) + actionpack (= 5.0.7.2) + activesupport (= 5.0.7.2) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (11.2.2) - rb-fsevent (0.9.7) - rb-inotify (0.9.7) - ffi (>= 0.5.0) - sass (3.4.22) - sass-rails (5.0.5) + rake (13.0.1) + rb-fsevent (0.10.4) + rb-inotify (0.10.1) + ffi (~> 1.0) + responders (3.0.0) + actionpack (>= 5.0) + railties (>= 5.0) + sass (3.7.4) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + sass-rails (5.0.7) railties (>= 4.0.0, < 6) sass (~> 3.1) sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - spring (1.7.2) - spring-watcher-listen (2.0.0) + sassc (2.3.0) + ffi (~> 1.9) + simple_form (5.0.2) + actionpack (>= 5.0) + activemodel (>= 5.0) + spring (2.1.0) + spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) - spring (~> 1.2) - sprockets (3.6.3) + spring (>= 1.2, < 3.0) + sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.1.1) + sprockets-rails (3.2.1) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - sqlite3 (1.3.11) - thor (0.19.1) - thread_safe (0.3.5) - tilt (2.0.5) - turbolinks (5.0.0) - turbolinks-source (~> 5) - turbolinks-source (5.0.0) - tzinfo (1.2.2) + sqlite3 (1.3.13) + thor (1.0.1) + thread_safe (0.3.6) + tilt (2.0.10) + turbolinks (5.2.1) + turbolinks-source (~> 5.2) + turbolinks-source (5.2.0) + tzinfo (1.2.7) thread_safe (~> 0.1) - uglifier (3.0.0) + uglifier (4.2.0) execjs (>= 0.3.0, < 3) - web-console (3.3.1) + warden (1.2.8) + rack (>= 2.0.6) + web-console (3.7.0) actionview (>= 5.0) activemodel (>= 5.0) - debug_inspector + bindex (>= 0.4.0) railties (>= 5.0) - websocket-driver (0.6.4) + websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.2) + websocket-extensions (0.1.4) PLATFORMS ruby DEPENDENCIES + bootstrap-sass byebug coffee-rails (~> 4.2) + devise jbuilder (~> 2.5) jquery-rails listen (~> 3.0.5) - puma (~> 3.0) + puma (= 4.2.1) rails (~> 5.0.0) sass-rails (~> 5.0) + simple_form spring spring-watcher-listen (~> 2.0.0) - sqlite3 + sqlite3 (= 1.3.13) turbolinks (~> 5) tzinfo-data uglifier (>= 1.3.0) web-console BUNDLED WITH - 1.12.5 + 2.1.4 diff --git a/README.md b/README.md index 7db80e4ca1..f0acd8ba70 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,3 @@ # README -This README would normally document whatever steps are necessary to get the -application up and running. - -Things you may want to cover: - -* Ruby version - -* System dependencies - -* Configuration - -* Database creation - -* Database initialization - -* How to run the test suite - -* Services (job queues, cache servers, search engines, etc.) - -* Deployment instructions - -* ... +第一週作業 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index b12018d099..ceee63822c 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -13,4 +13,6 @@ //= require jquery //= require jquery_ujs //= require turbolinks +//= require bootstrap/alert +//= require bootstrap/dropdown //= require_tree . diff --git a/app/assets/javascripts/jobs.coffee b/app/assets/javascripts/jobs.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/jobs.coffee @@ -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/ diff --git a/app/assets/javascripts/welcome.coffee b/app/assets/javascripts/welcome.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/welcome.coffee @@ -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/ diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.scss similarity index 93% rename from app/assets/stylesheets/application.css rename to app/assets/stylesheets/application.scss index 0ebd7fe829..461e0e7763 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.scss @@ -13,3 +13,6 @@ *= require_tree . *= require_self */ + + @import "bootstrap-sprockets"; + @import "bootstrap"; diff --git a/app/assets/stylesheets/jobs.scss b/app/assets/stylesheets/jobs.scss new file mode 100644 index 0000000000..750c307a15 --- /dev/null +++ b/app/assets/stylesheets/jobs.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the jobs controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/welcome.scss b/app/assets/stylesheets/welcome.scss new file mode 100644 index 0000000000..77ce11a740 --- /dev/null +++ b/app/assets/stylesheets/welcome.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the welcome controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/jobs_controller.rb b/app/controllers/jobs_controller.rb new file mode 100644 index 0000000000..1e8dd03563 --- /dev/null +++ b/app/controllers/jobs_controller.rb @@ -0,0 +1,49 @@ +class JobsController < ApplicationController + before_action :authenticate_user!, only: [:new, :create, :edit, :create, :destroy] + def index + @jobs = Job.all + end + + def new + @job = Job.new + end + + def show + @job = Job.find(params[:id]) + end + + def edit + @job = Job.find(params[:id]) + end + + def create + @job = Job.new(job_params) + if @job.save + redirect_to jobs_params + else + render :new + end + end + + def update + @job = Job.find(params[:id]) + + if @job.update(job_params) + redirect_to jobs_path, notice: 'update success' + else + render :edit + end + end + + def destroy + @job = Job.find(params[:id]) + @job.destroy + redirect_to jobs_path, alert: 'Are you sure' + end + + private + + def job_params + params.require(:job).permit(:title, :description) + end +end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb new file mode 100644 index 0000000000..c0fba57d7c --- /dev/null +++ b/app/controllers/welcome_controller.rb @@ -0,0 +1,5 @@ +class WelcomeController < ApplicationController + def index + flash[:notice] = "早安!你好!" + end +end diff --git a/app/helpers/flashes_helper.rb b/app/helpers/flashes_helper.rb new file mode 100644 index 0000000000..27bf164655 --- /dev/null +++ b/app/helpers/flashes_helper.rb @@ -0,0 +1,12 @@ +module FlashesHelper + FLASH_CLASS = { alert: "danger", notice: "success", warming: "warning"}.freeze + + def flash_class(key) + FLASH_CLASS.fetch key.to_sym, key + end + + def user_facting_flashes + flash.to_hash.slice "alert", "notice", "warning" + end + +end diff --git a/app/helpers/jobs_helper.rb b/app/helpers/jobs_helper.rb new file mode 100644 index 0000000000..44c7bf621c --- /dev/null +++ b/app/helpers/jobs_helper.rb @@ -0,0 +1,2 @@ +module JobsHelper +end diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb new file mode 100644 index 0000000000..eeead45fc9 --- /dev/null +++ b/app/helpers/welcome_helper.rb @@ -0,0 +1,2 @@ +module WelcomeHelper +end diff --git a/app/models/job.rb b/app/models/job.rb new file mode 100644 index 0000000000..3b93509d12 --- /dev/null +++ b/app/models/job.rb @@ -0,0 +1,3 @@ +class Job < ApplicationRecord + validates :title, presence: true +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000000..47567994e9 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,6 @@ +class User < ApplicationRecord + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :validatable +end diff --git a/app/views/common/_flashes.html.erb b/app/views/common/_flashes.html.erb new file mode 100644 index 0000000000..dcf3a8cad1 --- /dev/null +++ b/app/views/common/_flashes.html.erb @@ -0,0 +1,10 @@ +<% if flash.any? %> + + <% user_facting_flashes.each do |key, value| %> +
+ <%= link_to(job.title, job_path(job)) %> + | ++ <%= link_to("Edit", edit_job_path(job)) %> | + <%= link_to("Destroy", job_path(job), :method => :delete, :data => { confirm: "Are you sure?" }) %> + | ++ <%= job.created_at %> + | +
+ <%= simple_format(@job.description) %> +
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 659576bca5..f4cc8bc49c 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -9,6 +9,11 @@ +