rails-movie_review-copy-onebyone.md

rails new movie_review

git init

git add .

git commit -am"Initial Commit"

rails g scaffold Movie title:string description:text movie_length:string director:string rating:string

bundle

rake db:migrate

// 向 movies/new 中 new.html.haml 創(chuàng)建數(shù)據(jù)

// 向 Gemfile 中添加 gem 'devise'

bundle install

rails g devise:install

// config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

// root to: "movie#index"

<%= notice %>

<%= alert %>

// config.assets.initialize_on_precompile = false

rails g devise:views

rails g devise User

rake db:migrate

rails g migration add_user_id_to_movies user_id:integer

rake db:migrate

rails c

@movie = Movie.first

// 更改 movies_controller.rb 中 Movie.new 為 current_user.movies.build

// 添加 movies_controller.rb 中 before_action :authenticate_user!, except: [:index, :show]

// 添加 models/movie.rb 中 belongs_to :user

// 添加 models/user.rb 中 has_many :movies

// 向 movies/new 中創(chuàng)建 數(shù)據(jù)

rails c

@movie = Movie.first

@movie = Movie.last

@movie.each do |movie|

movie.user_id = 1

movie.save

end

@user = User.first

@movie = Movie.find(1)

@movie.user = @user

@movie

@movie.user_id = @user

@movie

@movie.user_id = 1

@movie.save

@movie

@movie = Movie.first

@movie.user_id = 1

@movie.save

@movie

git status

git add .

git commit -am"Add movie scaffold and users"

// 向 Gemfile 中添加 gem 'paperclip'

bundle install

// 向 movie.rb 中 添加 has_attached_file :image, styles: { medium: "400x600#" }

validates_attachment_content_type :image, content_type: /\Aimage/.*\Z/

rails g paperclip movie image

rake db:migrate

// 更改 _form.html.haml 內(nèi)容: @movie, html: { multipart: true } + 圖片上傳field

// 更改 show.html.haml 內(nèi)容:頭部添加 image_tag

// 向 movies_controller.rb 中 def movie_params 中 params.require(:movie).permit 添加 :image

// 向 app/views/movies/index.html.erb 中添加 image_tag

git s

git add .

git commit -m"Add paperclip for image upload"

git s

命令行輸入 sublime .gitignore ,然后.gitignore中添加 /public/systems/movies/images

// 向 Gemfile 中添加 gem 'bootstrap.sass'

bundle install

// 向 app/assets/stylesheets/application.css.scss 添加 @import "bootstrap-sprockets";

@import "bootstrap"; 以及寫些CSS代碼

// 向 app/assets/javascripts/application.js 中添加 //= require bootstrap-sprockets

// 創(chuàng)建 _head.html.haml show.html.haml

// 更改 app/views/movies/index.html.erb , 添加 <% if !user_signed_in? %>橫幅大頁面 和 <% @movies.each do |movie| %>循環(huán)

git s

git add .

git commit -m"Added bootstrap and styled"

git s

rails g scaffold Review rating:integer comment:text

rake db:migrate

// 給 reviews_controller.rb 中的 def create 添加 @review = Review.new(review_params) 和 if 判斷

rails g migration add_user_id_to_reviews user_id:integer

rake db:migrate

rails c

@review = Review.first

// 給 app/models/review.rb 添加 belongs_to :user

// 給 app/models/user.rb 添加 has_many :movies

has_many :reviews, dependent: :destroy

// 給 reviews_controller.rb 中的 def create 添加 @review.user_id = current_user.id

// 向 reviews/new 添加 數(shù)據(jù)

rails c

@review = Review.first

@movie = Movie.last

@movie

// 向 show.html.haml 添加 頁面模塊

// 完善 其他 views

git s

git add .

git commit -m"Review scaffold"

git s

rails g migration add_movie_id_to_reviews movie_id:integer

rails c

@review = Review.last

// 向 app/models/movie.rb 添加 has_many :reviews

// 向 app/models/review.rb 添加 belongs_to :movie

// 向 routes.rb 添加 resources :movies do

rake routes

// 給 reviews_controller.rb 添加 def set_movie , 修改 def create 中的if判斷條件 并添加 @review.movie_id = @movie.id , 頭部添加 before_action :set_movie

rails c

@movie = Movie.find(2)

@review = Review.last

// 完善 show.html.haml 和 edit.html.haml 和 new.html.haml頁面

// star-rating.js 應(yīng)用 到 _form.html.haml

// 完善 reviews_controller.rb 中的 def show

git s

git add .

git commit -m"Convert review ratings to stars"

git s

// 添加一個(gè)gem searchkick,對(duì) Gemfile , movies_controller.rb , movie.rb , _header.html.erb , search.html.erb , routes.rb 做的修改

git s

git add .

git commit -m"Add searchkick gem and implement search functionality"

git s

// 修改 一下 README

git s

git add .

git commit -m"Update README"

git s

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容