jdstore

1.fork 项目
步骤:
fork进入自己的git,然后

git clone git@github.com:XXXXX/job-listing.git (clone 到本地)
cd job-listing
cp config/database.yml.example config/database.yml (复制 database.yml.example)
bundle check ; bundle install (检查gem,安装gem)
git checkout -b version-1 (git checkout version-1)
rails s (跑起來)

(新建专案)
rm -rf suggestotron
rails new suggestotron
cd suggestotron
git init
git status
git add . (git add foo.txt 把名叫 foo.txt 的檔案加進追蹤修訂。
git add . (“git add dot”) 把所有新檔案和改過的檔案加進追蹤修訂,但「保留」你刪掉的檔案。
git add -A 全部加進追蹤修訂,包括刪掉的檔案。)
git commit -m “Added all the things”
-m “Added all the things 這個捷徑讓你可以直接寫下 commit message。你可以省略之,這樣子 git 會打開一個編輯器請你填寫詳細的 commit message。
rails generate scaffold topic title:string description:text
rake db:migrate
rails server
generate scaffold 告訴 Rails 去建立一堆檔案讓 topics 可以動。
topic 是告訴 rails 新的 Model 的名字是什麼。
title:string 是說 topics 有標題(title),它是一個字串(String)。
description:text 是說 topics 有內文(description),它是一段文字(Text)。(「字串」跟「文字」的差別?基本上「文字」是用來儲存可能會很長的字串。)

2.套上bootstrap
gem “bootstrap-sass”
bundle install (注意:修改完 Gemfile 都要執行 bundle install)
mv app/assets/stylesheets/application.css app/assets/stylesheets/application.scss
(將 application.css 更名為 application.scss)
application.scss中
@import “bootstrap-sprockets”;
@import “bootstrap”;

mkdir app/views/common
touch app/views/common/_navbar.html.erb
touch app/views/common/_footer.html.erb
修改全域 HTML 樣式 application.html.erb引入nav和footer

rails g controller welcome
touch app/views/welcome/index.html.erb
config/routes.rb
root ‘welcome#index’

app/assets/javascripts/application.js
  //= require bootstrap/alert

touch app/views/common/_flashes.html.erb
<% if flash.any? %>
<% user_facing_flashes.each do |key, value| %>



<%= value %>

<% end %>
<% end %>

touch app/helpers/flashes_helper.rb
module FlashesHelper
FLASH_CLASSES = { alert: “danger”, notice: “success”, warning: “warning”}.freeze

def flash_class(key)
  FLASH_CLASSES.fetch key.to_sym, key
end

def user_facing_flashes
  flash.to_hash.slice "alert", "notice","warning"
end

end

<%= render “common/flashes” %>

3.安装登入系统
gem “devise”
bundle install
rails g devise:install
rails g devise user
rake db:migrate

4.安装SimpleForm
gem “simple_form”
bundle install
rails generate simple_form:install –bootstrap
安裝 simple_form for bootstrap 的設定
這個指令會產生兩個檔案
config/initializers/simple_form.rb
config/initializers/simple_form_bootstrap.rb (這個是 Bootstrap 表單的「佈景」

5.rails g controller admin::products
rails g model product title:string description:text quantity:integer price:float
rake db:migrate

去做CRUD

6.增加is_admin
rails g migration add_is_admin_to_user
add_column :users, :is_admin, :boolean, default: false
rake db:migrate
def admin?
is_admin
end

7.上传压缩图
gem “carrierwave”
gem “mini_magick”
bundle install

rails g migration add_image_to_product
add_column :products,:image,:string
rake db:migrate
rails g uploader ImageUploader

在uploader中
include CarrierWave::MiniMagick
rocess resize_to_fit:[800,800]

version :thumb do
  process resize_to_fill:[200,200]
end

version :medium do
  process resize_to_fill:[400,400]
end

在Product中
mount_uploader :image,ImageUploader

在rails console中删除表
ActiveRecord::Migration.drop_table(:table_name)