From 56a5f0f2f8c81498681146b886d937e32b94b44e Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Thu, 19 Jul 2018 13:31:02 +0800 Subject: [PATCH 01/32] add tweets index action and view for public users --- app/views/tweets/index.html.erb | 1 + config/routes.rb | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 app/views/tweets/index.html.erb diff --git a/app/views/tweets/index.html.erb b/app/views/tweets/index.html.erb new file mode 100644 index 000000000..b9d397866 --- /dev/null +++ b/app/views/tweets/index.html.erb @@ -0,0 +1 @@ +

tweets

\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 90856d4fe..43a2ab7a9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,6 +2,8 @@ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html devise_for :users + root "tweets#index" + # 請依照專案指定規格來設定路由 end From d18831db2fb1700f2763653e27c009ae36c3da2b Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Wed, 25 Jul 2018 15:19:15 +0800 Subject: [PATCH 02/32] add tweets index action and view for admin --- app/views/admin/tweets/index.html.erb | 1 + config/routes.rb | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 app/views/admin/tweets/index.html.erb diff --git a/app/views/admin/tweets/index.html.erb b/app/views/admin/tweets/index.html.erb new file mode 100644 index 000000000..55c3a949b --- /dev/null +++ b/app/views/admin/tweets/index.html.erb @@ -0,0 +1 @@ +

tweets back

\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 43a2ab7a9..d111fb736 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,6 +4,11 @@ root "tweets#index" + namespace :admin do + root "tweets#index" + end + + # 請依照專案指定規格來設定路由 end From cc279bc140a38f04a0ffa31565822d4050ce88ac Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Wed, 25 Jul 2018 15:45:07 +0800 Subject: [PATCH 03/32] add login process and update view with login messages --- app/controllers/tweets_controller.rb | 2 ++ db/migrate/20180127070040_devise_create_users.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/tweets_controller.rb b/app/controllers/tweets_controller.rb index ad14115c1..a0f3966ff 100644 --- a/app/controllers/tweets_controller.rb +++ b/app/controllers/tweets_controller.rb @@ -1,4 +1,6 @@ class TweetsController < ApplicationController + before_action :authenticate_user! + def index @users # 基於測試規格,必須講定變數名稱,請用此變數中存放關注人數 Top 10 的使用者資料 diff --git a/db/migrate/20180127070040_devise_create_users.rb b/db/migrate/20180127070040_devise_create_users.rb index c1099cb8d..925e61690 100644 --- a/db/migrate/20180127070040_devise_create_users.rb +++ b/db/migrate/20180127070040_devise_create_users.rb @@ -31,7 +31,7 @@ def change # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts # t.string :unlock_token # Only if unlock strategy is :email or :both # t.datetime :locked_at - + t.string :role t.timestamps null: false end From 20c9011326ee47f1ebe43d6437e897d9c97a2914 Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Wed, 25 Jul 2018 16:45:40 +0800 Subject: [PATCH 04/32] can log in but admin not yet --- app/controllers/application_controller.rb | 6 +++++- app/controllers/tweets_controller.rb | 1 - app/models/user.rb | 6 +++++- app/views/layouts/application.html.erb | 2 +- db/seeds.rb | 2 ++ 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0da627f1a..aebb83d0e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,7 +1,11 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception - + before_action :authenticate_user! # 請參考 Devise 文件自訂表單後通過 Strong Parameters 的方法 # https://github.com/plataformatec/devise#strong-parameters # 注意有 sign_up 和 account_update 兩種參數要處理 + + + + end diff --git a/app/controllers/tweets_controller.rb b/app/controllers/tweets_controller.rb index a0f3966ff..c7e4e54c2 100644 --- a/app/controllers/tweets_controller.rb +++ b/app/controllers/tweets_controller.rb @@ -1,5 +1,4 @@ class TweetsController < ApplicationController - before_action :authenticate_user! def index diff --git a/app/models/user.rb b/app/models/user.rb index 6b05b8c21..0711414eb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -8,7 +8,11 @@ class User < ApplicationRecord # 需要 app/views/devise 裡找到樣板,加上 name 屬性 # 並參考 Devise 文件自訂表單後通過 Strong Parameters 的方法 - validates_presence_of :name + # 加上驗證 name 不能重覆 (關鍵字提示: uniqueness) + def admin? + self.role == "admin" + end + end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 952cb7a1b..724e6275d 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -15,7 +15,7 @@ <% end %>
  • <%= link_to('登出', destroy_user_session_path, method: :delete) %>
  • -
  • <%= link_to('修改個人資料', edit_user_path(current_user)) %>
  • +
  • <%= link_to('修改密碼', edit_user_registration_path) %>
  • <% else %>
  • <%= link_to('註冊', new_user_registration_path) %>
  • diff --git a/db/seeds.rb b/db/seeds.rb index 1beea2acc..f0dce931a 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,5 @@ # # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # Character.create(name: 'Luke', movie: movies.first) +User.create(email: "root@example.com", password: "123456", role: "admin") +puts "Default admin created!" From 05ee85bf3a83fb1c5af67831c73501f8109189d7 Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Wed, 25 Jul 2018 23:31:49 +0800 Subject: [PATCH 05/32] add user_profile name --- app/controllers/admin/tweets_controller.rb | 2 ++ app/controllers/application_controller.rb | 10 +++++++--- app/models/user.rb | 3 +++ app/views/devise/registrations/edit.html.erb | 2 +- app/views/devise/registrations/new.html.erb | 9 ++++++++- app/views/layouts/application.html.erb | 3 ++- db/seeds.rb | 2 +- 7 files changed, 24 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/tweets_controller.rb b/app/controllers/admin/tweets_controller.rb index 24a57566c..4c0d9b429 100644 --- a/app/controllers/admin/tweets_controller.rb +++ b/app/controllers/admin/tweets_controller.rb @@ -1,4 +1,6 @@ class Admin::TweetsController < Admin::BaseController + before_action :authenticate_user! + def index end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index aebb83d0e..dde7bbabb 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,11 +1,15 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception + before_action :configure_permitted_parameters, if: :devise_controller? before_action :authenticate_user! # 請參考 Devise 文件自訂表單後通過 Strong Parameters 的方法 # https://github.com/plataformatec/devise#strong-parameters # 注意有 sign_up 和 account_update 兩種參數要處理 + protected - - -end + def configure_permitted_parameters + devise_parameter_sanitizer.permit(:sign_up, keys: [:name]) + devise_parameter_sanitizer.permit(:account_update, keys: [:name]) + end +end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index 0711414eb..a081c76f8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -6,8 +6,11 @@ class User < ApplicationRecord mount_uploader :avatar, AvatarUploader + validates_presence_of :name + # 需要 app/views/devise 裡找到樣板,加上 name 屬性 # 並參考 Devise 文件自訂表單後通過 Strong Parameters 的方法 + validates_uniqueness_of :name # 加上驗證 name 不能重覆 (關鍵字提示: uniqueness) diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 10ed32a9e..aea2d3cc9 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -5,7 +5,7 @@
    <%= f.label :email %>
    - <%= f.email_field :email, autofocus: true, autocomplete: "email" %> + <%= f.email_field :email, autocomplete: "email" %>
    <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index 602803cff..cecd79187 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -5,9 +5,16 @@
    <%= f.label :email %>
    - <%= f.email_field :email, autofocus: true, autocomplete: "email" %> + <%= f.email_field :email, autocomplete: "email" %>
    + +
    + <%= f.label :name %>
    + <%= f.text_field :name, autofocus: true %> +
    + +
    <%= f.label :password %> <% if @minimum_password_length %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 724e6275d..49ab0a571 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -11,7 +11,7 @@ <% if current_user %> <% if current_user&.admin? %> -
  • <%= link_to 'Admin Panel', admin_restaurants_path %>
  • +
  • <%= link_to 'Admin Panel', admin_root_path %>
  • <% end %>
  • <%= link_to('登出', destroy_user_session_path, method: :delete) %>
  • @@ -21,6 +21,7 @@
  • <%= link_to('註冊', new_user_registration_path) %>
  • <%= link_to('登入', new_user_session_path) %>
  • <% end %> +

    <%= notice %>

    <%= alert %>

    <%= yield %> diff --git a/db/seeds.rb b/db/seeds.rb index f0dce931a..8bc123f17 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,5 +5,5 @@ # # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # Character.create(name: 'Luke', movie: movies.first) -User.create(email: "root@example.com", password: "123456", role: "admin") +User.create(email: "root@example.com", password: "123456", role: "admin",name: "root") puts "Default admin created!" From 47c81db86c4d2d2ea674b49ce1aa5007dda5927d Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Thu, 26 Jul 2018 00:31:42 +0800 Subject: [PATCH 06/32] controller/admin/index action & destroy action --- app/controllers/admin/tweets_controller.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/controllers/admin/tweets_controller.rb b/app/controllers/admin/tweets_controller.rb index 4c0d9b429..ed3331421 100644 --- a/app/controllers/admin/tweets_controller.rb +++ b/app/controllers/admin/tweets_controller.rb @@ -2,8 +2,13 @@ class Admin::TweetsController < Admin::BaseController before_action :authenticate_user! def index + @tweets = Tweet.order(created_at: :desc) end def destroy + tweet = Tweet.find(params[:id]) + tweet.destroy + flash[:alert] = "tweets delete!" + redirect_to admin_root_path end end From f3656c450b31ff8b2bcacdefa7d5eb36506c2ca5 Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Thu, 26 Jul 2018 00:56:25 +0800 Subject: [PATCH 07/32] set tweets route index&create --- app/controllers/admin/tweets_controller.rb | 2 +- config/routes.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/tweets_controller.rb b/app/controllers/admin/tweets_controller.rb index ed3331421..bfc5956b9 100644 --- a/app/controllers/admin/tweets_controller.rb +++ b/app/controllers/admin/tweets_controller.rb @@ -7,7 +7,7 @@ def index def destroy tweet = Tweet.find(params[:id]) - tweet.destroy + tweet.destroyad flash[:alert] = "tweets delete!" redirect_to admin_root_path end diff --git a/config/routes.rb b/config/routes.rb index d111fb736..73187d6eb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,9 +1,11 @@ Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html devise_for :users - root "tweets#index" + resources :tweets, only: [:index,:create] + root "tweet#index" + namespace :admin do root "tweets#index" end From c98706195a7b73fa0203c376420269bad10e2470 Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Thu, 26 Jul 2018 02:43:00 +0800 Subject: [PATCH 08/32] add tweet create action and view --- app/controllers/tweets_controller.rb | 23 ++++++++++++++++++++++- app/models/tweet.rb | 2 ++ app/views/tweets/index.html.erb | 21 ++++++++++++++++++++- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/app/controllers/tweets_controller.rb b/app/controllers/tweets_controller.rb index c7e4e54c2..93565fdb5 100644 --- a/app/controllers/tweets_controller.rb +++ b/app/controllers/tweets_controller.rb @@ -2,16 +2,37 @@ class TweetsController < ApplicationController def index - @users # 基於測試規格,必須講定變數名稱,請用此變數中存放關注人數 Top 10 的使用者資料 + @tweets = Tweet.order(created_at: :desc) + @tweet = Tweet.new + + @users + # 基於測試規格,必須講定變數名稱,請用此變數中存放關注人數 Top 10 的使用者資料 end def create + @tweet = Tweet.new(tweet_params) + if @tweet.save + flash[:notice] = "tweet was successfully created" + redirect_to :tweets + else + flash.now[:alert] = "tweet was failed to create" + render :index + end + end + def like end def unlike end + + + private + def tweet_params + params.require(:tweet).permit(:description) + end + end diff --git a/app/models/tweet.rb b/app/models/tweet.rb index 6715fada2..21f49015d 100644 --- a/app/models/tweet.rb +++ b/app/models/tweet.rb @@ -1,4 +1,6 @@ class Tweet < ApplicationRecord validates_length_of :description, maximum: 140 + belongs_to :user + #tweet只有一個作者 end diff --git a/app/views/tweets/index.html.erb b/app/views/tweets/index.html.erb index b9d397866..646cff1ab 100644 --- a/app/views/tweets/index.html.erb +++ b/app/views/tweets/index.html.erb @@ -1 +1,20 @@ -

    tweets

    \ No newline at end of file +<% if @tweet.errors.any? %> +

    We have some errors here !

    +
      + <% @tweet.errors.full_messages.each do |msg| %> +
    • <%= msg %>
    • + <% end %> +
    +<% end %> + + +<%=form_for @tweet do |f|%> + <%= f.label :description, "Description" %> + <%= f.text_area :description %> + + <%= f.submit %> +<% end %> + + + + From 0ec75290ba865d2437d4ac96e285cb40a05c9e23 Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Thu, 26 Jul 2018 14:19:25 +0800 Subject: [PATCH 09/32] tweet can actually created --- app/controllers/tweets_controller.rb | 1 + app/views/tweets/index.html.erb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/tweets_controller.rb b/app/controllers/tweets_controller.rb index 93565fdb5..a40ef6b5b 100644 --- a/app/controllers/tweets_controller.rb +++ b/app/controllers/tweets_controller.rb @@ -11,6 +11,7 @@ def index def create @tweet = Tweet.new(tweet_params) + @tweet.user = current_user if @tweet.save flash[:notice] = "tweet was successfully created" redirect_to :tweets diff --git a/app/views/tweets/index.html.erb b/app/views/tweets/index.html.erb index 646cff1ab..2c0278748 100644 --- a/app/views/tweets/index.html.erb +++ b/app/views/tweets/index.html.erb @@ -8,7 +8,7 @@ <% end %> -<%=form_for @tweet do |f|%> +<%=form_for [@user, @tweet] do |f|%> <%= f.label :description, "Description" %> <%= f.text_area :description %> From 44e5747e59bd7d9723f2a19a4f68aa8081fc60cc Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Thu, 26 Jul 2018 15:50:02 +0800 Subject: [PATCH 10/32] set model and routes --- app/controllers/tweets_controller.rb | 2 +- app/models/followship.rb | 2 ++ app/models/like.rb | 2 ++ app/models/reply.rb | 7 +++++++ app/models/tweet.rb | 11 ++++++++++- app/views/tweets/index.html.erb | 4 ++++ config/routes.rb | 5 +++++ 7 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app/controllers/tweets_controller.rb b/app/controllers/tweets_controller.rb index a40ef6b5b..ebc8c7dc8 100644 --- a/app/controllers/tweets_controller.rb +++ b/app/controllers/tweets_controller.rb @@ -5,7 +5,7 @@ def index @tweets = Tweet.order(created_at: :desc) @tweet = Tweet.new - @users + @users = User.order(followers_count: :desc).includes(:followers).limit(10) # 基於測試規格,必須講定變數名稱,請用此變數中存放關注人數 Top 10 的使用者資料 end diff --git a/app/models/followship.rb b/app/models/followship.rb index 1aed01396..5a5bc8e13 100644 --- a/app/models/followship.rb +++ b/app/models/followship.rb @@ -1,4 +1,6 @@ class Followship < ApplicationRecord validates :following_id, uniqueness: { scope: :user_id } + belongs_to :user + belongs_to :following end diff --git a/app/models/like.rb b/app/models/like.rb index d99b93a32..5771fe616 100644 --- a/app/models/like.rb +++ b/app/models/like.rb @@ -1,2 +1,4 @@ class Like < ApplicationRecord + belongs_to :user + belongs_to :tweet end diff --git a/app/models/reply.rb b/app/models/reply.rb index bae6f9463..fc1fd1b5c 100644 --- a/app/models/reply.rb +++ b/app/models/reply.rb @@ -1,2 +1,9 @@ class Reply < ApplicationRecord + + validates_presence_of :comment + + belongs_to :user + belongs_to :tweet + + end diff --git a/app/models/tweet.rb b/app/models/tweet.rb index 21f49015d..693af9a46 100644 --- a/app/models/tweet.rb +++ b/app/models/tweet.rb @@ -2,5 +2,14 @@ class Tweet < ApplicationRecord validates_length_of :description, maximum: 140 belongs_to :user #tweet只有一個作者 + + has_many :likes, dependent: :destroy + has_many :liked_users, through: :likes, source: :user -end + has_many :replies, dependent: :destroy + + def is_liked?(user) + self.liked_users.include?(user) + end + +end \ No newline at end of file diff --git a/app/views/tweets/index.html.erb b/app/views/tweets/index.html.erb index 2c0278748..123de69cf 100644 --- a/app/views/tweets/index.html.erb +++ b/app/views/tweets/index.html.erb @@ -16,5 +16,9 @@ <% end %> +
    + + + diff --git a/config/routes.rb b/config/routes.rb index 73187d6eb..fc40100f4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,13 +4,18 @@ root "tweets#index" resources :tweets, only: [:index,:create] + resources :replies, only: [:index,:create] root "tweet#index" + resources :followships, only: [:create,:destroy] namespace :admin do + resources :tweets, only: [:index, :destroy] + resources :users, only: [:index] root "tweets#index" end + # 請依照專案指定規格來設定路由 end From 3fd954e5c818f43a9f3cb32f46453969b20fc1eb Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Fri, 27 Jul 2018 01:49:31 +0800 Subject: [PATCH 11/32] create reply model and setup relation between restaurant, user and reply --- app/models/user.rb | 18 ++++++++++++++++-- app/views/tweets/index.html.erb | 8 ++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index a081c76f8..a0a494b1c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -7,12 +7,26 @@ class User < ApplicationRecord mount_uploader :avatar, AvatarUploader validates_presence_of :name - # 需要 app/views/devise 裡找到樣板,加上 name 屬性 # 並參考 Devise 文件自訂表單後通過 Strong Parameters 的方法 validates_uniqueness_of :name - # 加上驗證 name 不能重覆 (關鍵字提示: uniqueness) + + has_many :tweets, dependent: :destroy + + has_many :followships, dependent: :destroy + has_many :followings, through: :followships + + has_many :inverse_followships, class_name: "Followship", foreign_key: "following_id" + has_many :followers, through: :inverse_followships, source: :user + + has_many :likes, dependent: :destroy + has_many :liked_tweets, through: :likes, source: :tweet + + has_many :replies, dependent: :restrict_with_error + + + def admin? self.role == "admin" diff --git a/app/views/tweets/index.html.erb b/app/views/tweets/index.html.erb index 123de69cf..31044b846 100644 --- a/app/views/tweets/index.html.erb +++ b/app/views/tweets/index.html.erb @@ -18,7 +18,15 @@
    +<% @tweets.each do |tweet| %> + <%= image_tag (tweet.user.avatar), class: "usertweet-avatar" %> +
    <%= link_to tweet.user.name %>,<%= tweet.created_at.to_date %>,<%= tweet.created_at.strftime("%k:%M") %>
    + <%= simple_format tweet.description, style: "color:#808080" %> + + + +<% end %> From e95f4375c55a4c105b2f40ab3f4f77b6ab2b967e Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Fri, 27 Jul 2018 02:01:04 +0800 Subject: [PATCH 12/32] setup routes --- config/routes.rb | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index fc40100f4..de0e7c080 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,9 +3,24 @@ devise_for :users root "tweets#index" - resources :tweets, only: [:index,:create] - resources :replies, only: [:index,:create] - root "tweet#index" + resources :users, only: [:edit, :update] do + member do + get :tweets + get :followings + get :followers + get :likes + end + end + + resources :tweets, only: [:index,:create] do + resources :replies, only: [:index,:create] + member do + post :like + post :unlike + end + end + + resources :followships, only: [:create,:destroy] namespace :admin do @@ -16,6 +31,4 @@ - # 請依照專案指定規格來設定路由 - end From ed553d6c7765f2ddde03160b1ae0d07ca23a4589 Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Sat, 28 Jul 2018 15:01:56 +0800 Subject: [PATCH 13/32] profit#edit and page --- app/controllers/users_controller.rb | 8 ++++++++ app/views/layouts/application.html.erb | 1 + app/views/users/edit.html.erb | 13 +++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 app/views/users/edit.html.erb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 750e3c6b5..1310b145a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -4,6 +4,9 @@ def tweets end def edit + @user = current_user + #redirect_to tweets_user_path(@user) + end def update @@ -21,4 +24,9 @@ def likes @likes # 基於測試規格,必須講定變數名稱 end + def user_params + params.require(:user).permit(:name, :introduction, :avatar) + end + + end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 49ab0a571..a2745071f 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -14,6 +14,7 @@
  • <%= link_to 'Admin Panel', admin_root_path %>
  • <% end %>
  • +
  • <%= link_to 'Profile', user_path(current_user) %>
  • <%= link_to('登出', destroy_user_session_path, method: :delete) %>
  • <%= link_to('修改密碼', edit_user_registration_path) %>
  • diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb new file mode 100644 index 000000000..d2d87fdd8 --- /dev/null +++ b/app/views/users/edit.html.erb @@ -0,0 +1,13 @@ +<%= form_for @user do |f| %> +<%= f.label :avatar, "Photo" %> +<%= image_tag @user.avatar,width: '300px' if @user.avatar? %> +<%= f.file_field :avatar%> + +<%= f.label :name, "Name" %> +<%= f.text_field :name %> + +<%= f.label :introduction, "Introduction" %> +<%= f.text_area :introduction %> + +<%= f.submit "Update" %> +<% end %> \ No newline at end of file From fe631079a1f91f6bcfcc0f13b1d0ed1a2fe5efa5 Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Sat, 28 Jul 2018 15:48:20 +0800 Subject: [PATCH 14/32] profit#create and set bootstrap --- Gemfile | 2 ++ Gemfile.lock | 11 +++++++++++ app/assets/javascripts/application.js | 4 +++- app/assets/stylesheets/application.css | 4 ++-- app/controllers/users_controller.rb | 9 +++++++++ app/views/layouts/application.html.erb | 1 - 6 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index c1f1ee3e2..e4d478e2b 100644 --- a/Gemfile +++ b/Gemfile @@ -21,7 +21,9 @@ gem 'sqlite3' # Use Puma as the app server gem 'puma', '~> 3.7' # Use SCSS for stylesheets +gem 'bootstrap-sass', '~> 3.3.7' gem 'sass-rails', '~> 5.0' +gem 'jquery-rails' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' # See https://github.com/rails/execjs#readme for more supported runtimes diff --git a/Gemfile.lock b/Gemfile.lock index e55e9522f..29d8a4e5c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -41,11 +41,16 @@ GEM addressable (2.5.2) public_suffix (>= 2.0.2, < 4.0) arel (8.0.0) + autoprefixer-rails (9.0.0) + execjs bcrypt (3.1.11) bcrypt (3.1.11-java) bcrypt (3.1.11-x64-mingw32) bcrypt (3.1.11-x86-mingw32) bindex (0.5.0) + bootstrap-sass (3.3.7) + autoprefixer-rails (>= 5.2.1) + sass (>= 3.3.4) builder (3.2.3) byebug (10.0.0) capybara (2.17.0) @@ -97,6 +102,10 @@ GEM jbuilder (2.7.0) activesupport (>= 4.2.0) multi_json (>= 1.2) + jquery-rails (4.3.3) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -251,6 +260,7 @@ PLATFORMS x86-mswin32 DEPENDENCIES + bootstrap-sass (~> 3.3.7) byebug capybara (~> 2.13) carrierwave @@ -259,6 +269,7 @@ DEPENDENCIES factory_bot_rails ffaker jbuilder (~> 2.5) + jquery-rails listen (>= 3.0.5, < 3.2) puma (~> 3.7) rails (~> 5.1.4) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 46b20359f..7919e6468 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,4 +12,6 @@ // //= require rails-ujs //= require turbolinks -//= require_tree . +//= require jquery +//= require bootstrap-sprockets +//= require_tree . \ No newline at end of file diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index d05ea0f51..5e8f33d2a 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -10,6 +10,6 @@ * files in this directory. Styles in this file should be added after the last require_* statement. * It is generally better to create a new file per style scope. * - *= require_tree . - *= require_self */ +@import "bootstrap-sprockets"; +@import "bootstrap"; diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 1310b145a..ed8932e12 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,4 +1,5 @@ class UsersController < ApplicationController + before_action :set_user, only: [:edit, :update, :tweets, :followings, :followers, :likes] def tweets end @@ -10,6 +11,8 @@ def edit end def update + @user.update(user_params) + #redirect_to tweets_user_path(@user) end def followings @@ -24,6 +27,12 @@ def likes @likes # 基於測試規格,必須講定變數名稱 end + private + + def set_user + @user = User.find(params[:id]) + end + def user_params params.require(:user).permit(:name, :introduction, :avatar) end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index a2745071f..49ab0a571 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -14,7 +14,6 @@
  • <%= link_to 'Admin Panel', admin_root_path %>
  • <% end %>
  • -
  • <%= link_to 'Profile', user_path(current_user) %>
  • <%= link_to('登出', destroy_user_session_path, method: :delete) %>
  • <%= link_to('修改密碼', edit_user_registration_path) %>
  • From 413f32f333746d828c3ac6d02767e2791e39e3f1 Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Sat, 28 Jul 2018 17:06:34 +0800 Subject: [PATCH 15/32] reply_controller and view --- app/controllers/replies_controller.rb | 25 ++++++++++++++++++++++ app/views/replies/index.html.erb | 13 ++++++++++++ app/views/shared/_user_intro.html.erb | 30 +++++++++++++++++++++++++++ app/views/tweets/index.html.erb | 6 +++++- 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 app/views/replies/index.html.erb create mode 100644 app/views/shared/_user_intro.html.erb diff --git a/app/controllers/replies_controller.rb b/app/controllers/replies_controller.rb index a9b6a315b..ac3a57ba3 100644 --- a/app/controllers/replies_controller.rb +++ b/app/controllers/replies_controller.rb @@ -1,9 +1,34 @@ class RepliesController < ApplicationController def index + @tweet = Tweet.find(params[:tweet_id]) + @reply = Reply.new + @replies = @tweet.replies + @user = @tweet.user + @tweets = @user.tweets + #@followings = @user.followings + #@followers = @user.followers + #@likes = @user.likes end def create + @tweet = Tweet.find(params[:tweet_id]) + @reply = @tweet.replies.build(reply_params) + @reply.user = current_user + if @reply.save + flash[:notice] = "回覆成功!" + redirect_to tweet_replies_path(@tweet) + else + @tweet = Tweet.find(params[:tweet_id]) + flash[:alert] = "回覆不可以空白!!" + redirect_to tweet_replies_path(@tweet) + end + end + + private + + def reply_params + params.require(:reply).permit(:comment) end end diff --git a/app/views/replies/index.html.erb b/app/views/replies/index.html.erb new file mode 100644 index 000000000..c3607810a --- /dev/null +++ b/app/views/replies/index.html.erb @@ -0,0 +1,13 @@ + <%= render partial: "shared/user_intro" %> + +
    + +

    Tweets

    + + <%= image_tag (@tweet.user.avatar) %> +
    @<%= link_to @tweet.user.name, tweets_user_path(@user) %>,<%= @tweet.created_at.to_date %>,<%= @tweet.created_at.strftime("%k:%M") %>
    + <%= simple_format @tweet.description, style: "color:#808080" %> + + <%= link_to tweet_replies_path(@tweet) do %> + Reply + <% end %> \ No newline at end of file diff --git a/app/views/shared/_user_intro.html.erb b/app/views/shared/_user_intro.html.erb new file mode 100644 index 000000000..8f99e1dad --- /dev/null +++ b/app/views/shared/_user_intro.html.erb @@ -0,0 +1,30 @@ +
    +
    <%= image_tag (@user.avatar), class: "user-avatar" %>
    +

    <%= @user.name %>

    + <%= simple_format @user.introduction, style: "color:#4682B4" %> +

    <%= link_to tweets_user_path(@user), class: "twuser" do %> + Tweets + <% end %>

    +

    <%= link_to followings_user_path(@user), class: "twuser" do %> + Following + <% end %>

    +

    <%= link_to followers_user_path(@user), class: "twuser" do %> + Follower + <% end %>

    +

    <%= link_to likes_user_path(@user), class: "twuser" do %> + Like + <% end %>

    + + + <% if @user.email == current_user.email %> + <%= link_to 'Edit Profile', edit_user_path(@user), class: "btn btn-primary btn-lg" %> + <% else %> + + + + + <% end %> + + + +
    \ No newline at end of file diff --git a/app/views/tweets/index.html.erb b/app/views/tweets/index.html.erb index 31044b846..5e74c2a1b 100644 --- a/app/views/tweets/index.html.erb +++ b/app/views/tweets/index.html.erb @@ -26,7 +26,11 @@ <%= simple_format tweet.description, style: "color:#808080" %> - + <%= link_to tweet_replies_path(tweet) do %> + Reply + <% end %> + + <% end %> From 33f18f5e4e5bbf959c2cab7509ae68253ba55560 Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Sat, 28 Jul 2018 17:21:24 +0800 Subject: [PATCH 16/32] reply success --- app/views/replies/index.html.erb | 34 +++++++++++++++++++++++---- app/views/shared/_user_intro.html.erb | 8 ++++--- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/app/views/replies/index.html.erb b/app/views/replies/index.html.erb index c3607810a..a185e5284 100644 --- a/app/views/replies/index.html.erb +++ b/app/views/replies/index.html.erb @@ -1,13 +1,39 @@ +
    +
    + <%= render partial: "shared/user_intro" %> -
    - +

    Tweets

    - <%= image_tag (@tweet.user.avatar) %> + <%= image_tag (@tweet.user.avatar), class: "usertweet-avatar" %>
    @<%= link_to @tweet.user.name, tweets_user_path(@user) %>,<%= @tweet.created_at.to_date %>,<%= @tweet.created_at.strftime("%k:%M") %>
    <%= simple_format @tweet.description, style: "color:#808080" %> <%= link_to tweet_replies_path(@tweet) do %> Reply - <% end %> \ No newline at end of file + <% end %> + + + + +

    Replies

    + <% @replies.each do |reply| %> +
    + <%= image_tag (reply.user.avatar), class: "usertweet-avatar" %> +
    @<%= link_to reply.user.name, tweets_user_path(@user) %>,<%= reply.created_at.to_date %>,<%= reply.created_at.strftime("%k:%M") %>
    + <%= simple_format reply.comment, style: "color:#808080" %> +
    + <% end %> + + <%= form_for [@tweet, @reply] do |f| %> +
    + <%= f.text_area :comment, class: "form-control", rows: "5" %> +
    +
    + <%= f.submit "Reply", class: "btn btn-primary btn-lg movebtn" %> +
    + <% end %> + +
    +
    \ No newline at end of file diff --git a/app/views/shared/_user_intro.html.erb b/app/views/shared/_user_intro.html.erb index 8f99e1dad..74de8c086 100644 --- a/app/views/shared/_user_intro.html.erb +++ b/app/views/shared/_user_intro.html.erb @@ -19,9 +19,11 @@ <% if @user.email == current_user.email %> <%= link_to 'Edit Profile', edit_user_path(@user), class: "btn btn-primary btn-lg" %> <% else %> - - - + <% if @user.following?(current_user)%> + <%= link_to 'Unfollow', followship_path(@user), method: :delete, class: "btn btn-primary btn-lg" %> + <% else %> + <%= link_to 'Follow', followships_path(following_id: @user), method: :post, class: "btn btn-primary btn-lg btn-block"%> + <% end %> <% end %> From 6ed97c0052ff70522cc4ff207827655925629055 Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Sat, 28 Jul 2018 17:51:19 +0800 Subject: [PATCH 17/32] bootstrap setting --- app/assets/stylesheets/application.css | 1 + app/assets/stylesheets/style.scss | 69 ++++++++++++++++++++++++++ app/views/layouts/application.html.erb | 65 +++++++++++++++++++----- 3 files changed, 122 insertions(+), 13 deletions(-) create mode 100644 app/assets/stylesheets/style.scss diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 5e8f33d2a..ade33e787 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -13,3 +13,4 @@ */ @import "bootstrap-sprockets"; @import "bootstrap"; +@import "style"; diff --git a/app/assets/stylesheets/style.scss b/app/assets/stylesheets/style.scss new file mode 100644 index 000000000..caedd63df --- /dev/null +++ b/app/assets/stylesheets/style.scss @@ -0,0 +1,69 @@ +.edit_user img { + width: 250px; + margin: 10px; +} + +.user-avatar{ + width: 250px; + margin: 10px; +} + +.usertweet-avatar{ + margin: 5px; + width: 70px; + height: 70px; + float: left; +} + +.twpanel{ + min-height: 80px; +} + +.ppanel{ + min-height: 250px; +} + +.twuser{ + color:#666666; +} + +h2{ + color:#008B8B; +} + +h5{ + color:#4682B4; +} + +h3{ + color:#4682B4; +} + +.movebtn{ + float: right; +} + +.twnavbar{ + background-color:#ADD8E6; +} + +.twnavbar-logo{ + color: #000000; + height: 20px; +} + +.twnavbar-ul { + font-size: 20px; + color: #008B8B; + margin-top: 10px; +} + +.twnavbar-ul img { + height: 40px; + position:relative; top:-5px; left:0px; +} + +.navbar-nav > li > a { + padding-top: 10px; + padding-bottom: 0px; +} \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 49ab0a571..51e2f9ab4 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -9,21 +9,60 @@ - <% if current_user %> - <% if current_user&.admin? %> -
  • <%= link_to 'Admin Panel', admin_root_path %>
  • - <% end %> -
  • -
  • <%= link_to('登出', destroy_user_session_path, method: :delete) %>
  • - -
  • <%= link_to('修改密碼', edit_user_registration_path) %>
  • - <% else %> -
  • <%= link_to('註冊', new_user_registration_path) %>
  • -
  • <%= link_to('登入', new_user_session_path) %>
  • + + + <% if flash[:notice] %> +
    +
    + +
    +
    + <% end %> + + <% if flash[:alert] %> +
    +
    + +
    +
    <% end %> -

    <%= notice %>

    -

    <%= alert %>

    <%= yield %> + From 446674738b26b9a63e799f6f313cd4077cde7e36 Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Sun, 29 Jul 2018 16:56:18 +0800 Subject: [PATCH 18/32] reply OK,now proceed follow action --- app/controllers/followships_controller.rb | 19 +++++++++++++++ app/controllers/users_controller.rb | 29 ++++++++++++++++++----- app/models/followship.rb | 2 +- app/views/replies/index.html.erb | 2 +- app/views/shared/_user_intro.html.erb | 2 +- app/views/users/tweets.html.erb | 19 +++++++++++++++ 6 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 app/views/users/tweets.html.erb diff --git a/app/controllers/followships_controller.rb b/app/controllers/followships_controller.rb index 05f01b552..d0b2c36a3 100644 --- a/app/controllers/followships_controller.rb +++ b/app/controllers/followships_controller.rb @@ -1,7 +1,26 @@ class FollowshipsController < ApplicationController def create + @user = User.find(params[:following_id]) + if @user == current_user + flash[:notice] = "Can't follow self!" + redirect_to root_path + else + @followship = current_user.followships.build(following_id: params[:following_id]) + + if @followship.save + flash[:notice] = "Successfully followed" + redirect_back(fallback_location: root_path) + else + flash[:alert] = @followship.errors.full_messages.to_sentence + redirect_back(fallback_location: root_path) + end + end end def destroy + @followship = current_user.followships.where(following_id: params[:id]).first + @followship.destroy + flash[:alert] = "Followship destroyed" + redirect_back(fallback_location: root_path) end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ed8932e12..17fef5f4e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2,31 +2,48 @@ class UsersController < ApplicationController before_action :set_user, only: [:edit, :update, :tweets, :followings, :followers, :likes] def tweets + @tweets = @user.tweets + @order_user_tweets = @user.tweets.order(created_at: :desc) + end def edit - @user = current_user - #redirect_to tweets_user_path(@user) - + unless @user == current_user + redirect_to tweets_user_path(@user) + end end + def update @user.update(user_params) #redirect_to tweets_user_path(@user) end def followings - @followings # 基於測試規格,必須講定變數名稱 + @followings = @user.followings.order('followships.created_at DESC') + # 基於測試規格,必須講定變數名稱 + @tweets = @user.tweets + @followers = @user.followers + @likes = @user.likes end def followers - @followers # 基於測試規格,必須講定變數名稱 + @followers = @user.followers.order('followships.created_at DESC') + # 基於測試規格,必須講定變數名稱 + @tweets = @user.tweets + @followings = @user.followings + @likes = @user.likes end def likes - @likes # 基於測試規格,必須講定變數名稱 + @likes = @user.liked_tweets.order('likes.created_at DESC') + # 基於測試規格,必須講定變數名稱 + @tweets = @user.tweets + @followings = @user.followings + @followers = @user.followers end + private def set_user diff --git a/app/models/followship.rb b/app/models/followship.rb index 5a5bc8e13..8fd5ef174 100644 --- a/app/models/followship.rb +++ b/app/models/followship.rb @@ -1,6 +1,6 @@ class Followship < ApplicationRecord validates :following_id, uniqueness: { scope: :user_id } belongs_to :user - belongs_to :following + belongs_to :following, class_name: "User" end diff --git a/app/views/replies/index.html.erb b/app/views/replies/index.html.erb index a185e5284..50a7545c9 100644 --- a/app/views/replies/index.html.erb +++ b/app/views/replies/index.html.erb @@ -31,7 +31,7 @@ <%= f.text_area :comment, class: "form-control", rows: "5" %>
    - <%= f.submit "Reply", class: "btn btn-primary btn-lg movebtn" %> + <%= f.submit "Reply"%>
    <% end %> diff --git a/app/views/shared/_user_intro.html.erb b/app/views/shared/_user_intro.html.erb index 74de8c086..f60319733 100644 --- a/app/views/shared/_user_intro.html.erb +++ b/app/views/shared/_user_intro.html.erb @@ -18,7 +18,7 @@ <% if @user.email == current_user.email %> <%= link_to 'Edit Profile', edit_user_path(@user), class: "btn btn-primary btn-lg" %> - <% else %> + <% if @user.following?(current_user)%> <%= link_to 'Unfollow', followship_path(@user), method: :delete, class: "btn btn-primary btn-lg" %> <% else %> diff --git a/app/views/users/tweets.html.erb b/app/views/users/tweets.html.erb new file mode 100644 index 000000000..bb87a0668 --- /dev/null +++ b/app/views/users/tweets.html.erb @@ -0,0 +1,19 @@ +
    +
    + + <%= render partial: "shared/user_intro" %> + +
    + <% @order_user_tweets.each do |tweet| %> +
    + <%= image_tag (tweet.user.avatar), class: "usertweet-avatar" %> +
    @<%= link_to tweet.user.name, tweets_user_path(@user) %>,<%= tweet.created_at.to_date %>,<%= tweet.created_at.strftime("%k:%M") %>
    + <%= simple_format tweet.description, style: "color:#808080" %> +
    + <% end %> +
    + + + +
    +
    From 05067b8a2618df067b1906a504ac3bd30c1db324 Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Sun, 29 Jul 2018 17:12:38 +0800 Subject: [PATCH 19/32] definte following? action --- app/models/user.rb | 4 ++++ app/views/shared/_user_intro.html.erb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index a0a494b1c..9a51b8cf1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -31,5 +31,9 @@ class User < ApplicationRecord def admin? self.role == "admin" end + + def following?(user) + self.followers.include?(user) + end end diff --git a/app/views/shared/_user_intro.html.erb b/app/views/shared/_user_intro.html.erb index f60319733..379e723d5 100644 --- a/app/views/shared/_user_intro.html.erb +++ b/app/views/shared/_user_intro.html.erb @@ -16,7 +16,7 @@ <% end %>

    - <% if @user.email == current_user.email %> + <% if @user.email == current_user.email %> <%= link_to 'Edit Profile', edit_user_path(@user), class: "btn btn-primary btn-lg" %> <% if @user.following?(current_user)%> From 0bfb0a1dd4ecb66a36a8584f2339bf89a2e68c08 Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Sun, 29 Jul 2018 20:54:16 +0800 Subject: [PATCH 20/32] fix bootstarp and root_index view and like action --- .../{application.css => application.scss} | 0 app/assets/stylesheets/style.scss | 4 -- app/controllers/admin/tweets_controller.rb | 2 +- app/controllers/tweets_controller.rb | 11 ++++- app/controllers/users_controller.rb | 2 +- app/views/layouts/application.html.erb | 6 +-- app/views/shared/_user_intro.html.erb | 1 - app/views/tweets/index.html.erb | 42 ++++++++++++------- app/views/users/edit.html.erb | 38 ++++++++++++----- 9 files changed, 69 insertions(+), 37 deletions(-) rename app/assets/stylesheets/{application.css => application.scss} (100%) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.scss similarity index 100% rename from app/assets/stylesheets/application.css rename to app/assets/stylesheets/application.scss diff --git a/app/assets/stylesheets/style.scss b/app/assets/stylesheets/style.scss index caedd63df..66edd6c39 100644 --- a/app/assets/stylesheets/style.scss +++ b/app/assets/stylesheets/style.scss @@ -47,10 +47,6 @@ h3{ background-color:#ADD8E6; } -.twnavbar-logo{ - color: #000000; - height: 20px; -} .twnavbar-ul { font-size: 20px; diff --git a/app/controllers/admin/tweets_controller.rb b/app/controllers/admin/tweets_controller.rb index bfc5956b9..d489598b0 100644 --- a/app/controllers/admin/tweets_controller.rb +++ b/app/controllers/admin/tweets_controller.rb @@ -7,7 +7,7 @@ def index def destroy tweet = Tweet.find(params[:id]) - tweet.destroyad + tweet.destroyed flash[:alert] = "tweets delete!" redirect_to admin_root_path end diff --git a/app/controllers/tweets_controller.rb b/app/controllers/tweets_controller.rb index ebc8c7dc8..cd2cc813a 100644 --- a/app/controllers/tweets_controller.rb +++ b/app/controllers/tweets_controller.rb @@ -13,10 +13,10 @@ def create @tweet = Tweet.new(tweet_params) @tweet.user = current_user if @tweet.save - flash[:notice] = "tweet was successfully created" + flash[:notice] = "推播建立!" redirect_to :tweets else - flash.now[:alert] = "tweet was failed to create" + flash.now[:alert] = "推播不可空白!" render :index end @@ -24,9 +24,16 @@ def create def like + @tweet = Tweet.find(params[:id]) + @tweet.likes.create!(user: current_user) + redirect_to tweets_path end def unlike + @tweet = Tweet.find(params[:id]) + like = Like.where(tweet: @tweet, user: current_user) + like.destroy_all + redirect_to tweets_path end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 17fef5f4e..0dacfe8c5 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -16,7 +16,7 @@ def edit def update @user.update(user_params) - #redirect_to tweets_user_path(@user) + redirect_to tweets_user_path(@user) end def followings diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 51e2f9ab4..938ca69ff 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -19,16 +19,16 @@ -

    <%= link_to 'EZ twitter', root_path, class: "twnavbar-logo" %>

    +

    <%= link_to 'EZ twitter', root_path %>

    From c612df28c63e4dd2dcabcf72d87479ce59610f3c Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Mon, 30 Jul 2018 11:16:59 +0800 Subject: [PATCH 22/32] routes and root fix --- app/views/tweets/index.html.erb | 1 + config/routes.rb | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/views/tweets/index.html.erb b/app/views/tweets/index.html.erb index 7e66f59fd..0a8bde5ca 100644 --- a/app/views/tweets/index.html.erb +++ b/app/views/tweets/index.html.erb @@ -45,6 +45,7 @@ <% end %> <% end %> + <% end %> diff --git a/config/routes.rb b/config/routes.rb index de0e7c080..fffa1aa92 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,7 +20,6 @@ end end - resources :followships, only: [:create,:destroy] namespace :admin do @@ -29,6 +28,4 @@ root "tweets#index" end - - end From 60b2f0038e7f99342cfc79a7a8385996e35c5a2c Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Mon, 30 Jul 2018 12:42:56 +0800 Subject: [PATCH 23/32] Index_Popular --- app/controllers/replies_controller.rb | 2 +- app/controllers/tweets_controller.rb | 1 - app/controllers/users_controller.rb | 3 ++ app/models/followship.rb | 3 +- app/models/like.rb | 2 +- app/models/reply.rb | 2 +- app/models/tweet.rb | 2 +- app/views/tweets/index.html.erb | 44 +++++++++++---------------- 8 files changed, 26 insertions(+), 33 deletions(-) diff --git a/app/controllers/replies_controller.rb b/app/controllers/replies_controller.rb index ac3a57ba3..308fd11ab 100644 --- a/app/controllers/replies_controller.rb +++ b/app/controllers/replies_controller.rb @@ -20,7 +20,7 @@ def create redirect_to tweet_replies_path(@tweet) else @tweet = Tweet.find(params[:tweet_id]) - flash[:alert] = "回覆不可以空白!!" + flash[:alert] = "回覆不可空白!!" redirect_to tweet_replies_path(@tweet) end end diff --git a/app/controllers/tweets_controller.rb b/app/controllers/tweets_controller.rb index cd2cc813a..8fbfb49dc 100644 --- a/app/controllers/tweets_controller.rb +++ b/app/controllers/tweets_controller.rb @@ -4,7 +4,6 @@ class TweetsController < ApplicationController def index @tweets = Tweet.order(created_at: :desc) @tweet = Tweet.new - @users = User.order(followers_count: :desc).includes(:followers).limit(10) # 基於測試規格,必須講定變數名稱,請用此變數中存放關注人數 Top 10 的使用者資料 end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0dacfe8c5..ea958a6fc 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -4,6 +4,9 @@ class UsersController < ApplicationController def tweets @tweets = @user.tweets @order_user_tweets = @user.tweets.order(created_at: :desc) + @followings = @user.followings + @followers = @user.followers + @likes = @user.likes end diff --git a/app/models/followship.rb b/app/models/followship.rb index 8fd5ef174..10e336a93 100644 --- a/app/models/followship.rb +++ b/app/models/followship.rb @@ -1,6 +1,5 @@ class Followship < ApplicationRecord validates :following_id, uniqueness: { scope: :user_id } belongs_to :user - belongs_to :following, class_name: "User" - + belongs_to :following, class_name: "User", counter_cache: :followers_count end diff --git a/app/models/like.rb b/app/models/like.rb index 5771fe616..42d487577 100644 --- a/app/models/like.rb +++ b/app/models/like.rb @@ -1,4 +1,4 @@ class Like < ApplicationRecord belongs_to :user - belongs_to :tweet + belongs_to :tweet, counter_cache: true end diff --git a/app/models/reply.rb b/app/models/reply.rb index fc1fd1b5c..74a2ded36 100644 --- a/app/models/reply.rb +++ b/app/models/reply.rb @@ -3,7 +3,7 @@ class Reply < ApplicationRecord validates_presence_of :comment belongs_to :user - belongs_to :tweet + belongs_to :tweet, counter_cache: true end diff --git a/app/models/tweet.rb b/app/models/tweet.rb index 693af9a46..a11146bc7 100644 --- a/app/models/tweet.rb +++ b/app/models/tweet.rb @@ -1,6 +1,6 @@ class Tweet < ApplicationRecord validates_length_of :description, maximum: 140 - belongs_to :user + belongs_to :user, counter_cache: true #tweet只有一個作者 has_many :likes, dependent: :destroy diff --git a/app/views/tweets/index.html.erb b/app/views/tweets/index.html.erb index 0a8bde5ca..6998120e1 100644 --- a/app/views/tweets/index.html.erb +++ b/app/views/tweets/index.html.erb @@ -1,13 +1,3 @@ -<% if @tweet.errors.any? %> -

    We have some errors here !

    -
      - <% @tweet.errors.full_messages.each do |msg| %> -
    • <%= msg %>
    • - <% end %> -
    -<% end %> - -
    @@ -45,25 +35,27 @@ <% end %> <% end %>
    - + <% end %>
    - - - - - - - - - - - - - - - +
    +

    Popular

    + <% @users.each do |user| %> +
    + <%= image_tag (user.avatar), class: "usertweet-avatar" %> +

    @<%= link_to user.name, tweets_user_path(user) %>

    + <%= simple_format user.introduction, style: "color:#808080" %> + <% if user != current_user %> + <% if user.following?(current_user)%> + <%= link_to 'Unfollow', followship_path(user), method: :delete, class: "btn btn-primary movebtn" %> + <% else %> + <%= link_to 'Follow', followships_path(following_id: user), method: :post, class: "btn btn-primary movebtn" %> + <% end %> + <% end %> +
    + <% end %> +
    From d824bc345bd073977256e1129a43d47c511f5800 Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Mon, 30 Jul 2018 13:10:27 +0800 Subject: [PATCH 24/32] index/popular and count action --- app/assets/stylesheets/style.scss | 2 +- app/views/tweets/index.html.erb | 4 ++-- db/migrate/20180730050340_add_tweets_count_to_users.rb | 5 +++++ db/schema.rb | 3 ++- 4 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20180730050340_add_tweets_count_to_users.rb diff --git a/app/assets/stylesheets/style.scss b/app/assets/stylesheets/style.scss index 66edd6c39..f1830ebd5 100644 --- a/app/assets/stylesheets/style.scss +++ b/app/assets/stylesheets/style.scss @@ -20,7 +20,7 @@ } .ppanel{ - min-height: 250px; + min-height: 160px; } .twuser{ diff --git a/app/views/tweets/index.html.erb b/app/views/tweets/index.html.erb index 6998120e1..2a62fea05 100644 --- a/app/views/tweets/index.html.erb +++ b/app/views/tweets/index.html.erb @@ -8,16 +8,16 @@
    <%= f.submit "推吧推吧", class: "btn btn-primary movebtn" %> +
    <% end %> - +


    <% @tweets.each do |tweet| %>
    - <%= image_tag (tweet.user.avatar), class: "usertweet-avatar" %>
    <%= link_to tweet.user.name, tweets_user_path(tweet.user) %>,<%= tweet.created_at.to_date %>,<%= tweet.created_at.strftime("%k:%M") %>
    <%= simple_format tweet.description, style: "color:#808080" %> diff --git a/db/migrate/20180730050340_add_tweets_count_to_users.rb b/db/migrate/20180730050340_add_tweets_count_to_users.rb new file mode 100644 index 000000000..abb23c746 --- /dev/null +++ b/db/migrate/20180730050340_add_tweets_count_to_users.rb @@ -0,0 +1,5 @@ +class AddTweetsCountToUsers < ActiveRecord::Migration[5.1] + def change + add_column :users, :tweets_count, :integer, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index 6a6842c86..5f73a4bc8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180201102838) do +ActiveRecord::Schema.define(version: 20180730050340) do create_table "followships", force: :cascade do |t| t.integer "user_id" @@ -66,6 +66,7 @@ t.integer "likes_count", default: 0 t.string "role", default: "normal" t.integer "followers_count", default: 0 + t.integer "tweets_count", default: 0 t.index ["email"], name: "index_users_on_email", unique: true t.index ["name"], name: "index_users_on_name", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true From 27100d9d1e323ab6ec717d5ff3e5756c09173d7e Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Mon, 30 Jul 2018 13:39:37 +0800 Subject: [PATCH 25/32] profix's three path OK --- app/views/shared/_user_intro.html.erb | 6 +++--- app/views/users/followers.html.erb | 28 ++++++++++++++++++++++++ app/views/users/followings.html.erb | 28 ++++++++++++++++++++++++ app/views/users/likes.html.erb | 31 +++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 app/views/users/followers.html.erb create mode 100644 app/views/users/followings.html.erb create mode 100644 app/views/users/likes.html.erb diff --git a/app/views/shared/_user_intro.html.erb b/app/views/shared/_user_intro.html.erb index 1295da249..b0d748658 100644 --- a/app/views/shared/_user_intro.html.erb +++ b/app/views/shared/_user_intro.html.erb @@ -17,12 +17,12 @@ <% if @user.email == current_user.email %> - <%= link_to 'Edit Profile', edit_user_path(@user), class: "btn btn-primary btn-lg" %> + <%= link_to 'Edit Profile', edit_user_path(@user), class: "btn btn-primary" %> <% if @user.following?(current_user)%> - <%= link_to 'Unfollow', followship_path(@user), method: :delete, class: "btn btn-primary btn-lg" %> + <%= link_to 'Unfollow', followship_path(@user), method: :delete, class: "btn btn-primary" %> <% else %> - <%= link_to 'Follow', followships_path(following_id: @user), method: :post, class: "btn btn-primary btn-lg btn-block"%> + <%= link_to 'Follow', followships_path(following_id: @user), method: :post, class: "btn btn-primary"%> <% end %> <% end %> diff --git a/app/views/users/followers.html.erb b/app/views/users/followers.html.erb new file mode 100644 index 000000000..69175e283 --- /dev/null +++ b/app/views/users/followers.html.erb @@ -0,0 +1,28 @@ +
    +
    + + <%= render partial: "shared/user_intro" %> + +
    +

    Follower

    + <% @followers.each do |user| %> +
    +
    + <%= image_tag (user.avatar), class: "usertweet-avatar" %> +

    @<%= link_to user.name, tweets_user_path(user) %>

    + <%= simple_format user.introduction, style: "color:#808080" %> + <% if user != current_user %> + <% if user.following?(current_user)%> + <%= link_to 'Unfollow', followship_path(user), method: :delete, class: "btn btn-primary movebtn" %> + <% else %> + <%= link_to 'Follow', followships_path(following_id: user), method: :post, class: "btn btn-primary movebtn" %> + <% end %> + <% end %> +
    +
    + <% end %> +
    + +
    +
    +
    \ No newline at end of file diff --git a/app/views/users/followings.html.erb b/app/views/users/followings.html.erb new file mode 100644 index 000000000..990dd8dd7 --- /dev/null +++ b/app/views/users/followings.html.erb @@ -0,0 +1,28 @@ +
    +
    + + <%= render partial: "shared/user_intro" %> + +
    +

    Following

    + <% @followings.each do |user| %> +
    +
    + <%= image_tag (user.avatar), class: "usertweet-avatar" %> +

    @<%= link_to user.name, tweets_user_path(user) %>

    + <%= simple_format user.introduction, style: "color:#808080" %> + <% if user != current_user %> + <% if user.following?(current_user)%> + <%= link_to 'Unfollow', followship_path(user), method: :delete, class: "btn btn-primary movebtn" %> + <% else %> + <%= link_to 'Follow', followships_path(following_id: user), method: :post, class: "btn btn-primary movebtn" %> + <% end %> + <% end %> +
    +
    + <% end %> +
    + +
    +
    + \ No newline at end of file diff --git a/app/views/users/likes.html.erb b/app/views/users/likes.html.erb new file mode 100644 index 000000000..ce1b94003 --- /dev/null +++ b/app/views/users/likes.html.erb @@ -0,0 +1,31 @@ +
    +
    + + <%= render partial: "shared/user_intro" %> + +
    +

    Like

    + <% @likes.each do |tweet| %> +
    + <%= image_tag (tweet.user.avatar), class: "usertweet-avatar" %> +
    @<%= link_to tweet.user.name, tweets_user_path(tweet.user) %>,<%= tweet.created_at.to_date %>,<%= tweet.created_at.strftime("%k:%M") %>
    + <%= simple_format tweet.description, style: "color:#808080" %> + <%= link_to tweet_replies_path(tweet) do %> + Reply(<%= tweet.replies.count %>) + <% end %> + <% if tweet.is_liked?(current_user) %> + <%= link_to unlike_tweet_path(tweet), method: :post, class: "text-danger" do %> + Unlike(<%= tweet.likes_count %>) + <% end %> + <% else %> + <%= link_to like_tweet_path(tweet), method: :post, class: "text-danger" do %> + Like(<%= tweet.likes_count %>) + <% end %> + <% end %> +
    + <% end %> +
    + + +
    +
    \ No newline at end of file From 88a1a1cae1768900cf8b4024c9f9df3a024dba85 Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Mon, 30 Jul 2018 14:05:28 +0800 Subject: [PATCH 26/32] admin page OK --- app/controllers/admin/base_controller.rb | 10 ++++++- app/controllers/admin/tweets_controller.rb | 4 +-- app/controllers/admin/users_controller.rb | 1 + app/views/admin/tweets/index.html.erb | 32 +++++++++++++++++++++- app/views/admin/users/index.html.erb | 29 ++++++++++++++++++++ 5 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 app/views/admin/users/index.html.erb diff --git a/app/controllers/admin/base_controller.rb b/app/controllers/admin/base_controller.rb index 4a89583f5..8014fc291 100644 --- a/app/controllers/admin/base_controller.rb +++ b/app/controllers/admin/base_controller.rb @@ -1,3 +1,11 @@ class Admin::BaseController < ApplicationController - + before_action :authenticate_admin + #admin才可以進後台 + private + def authenticate_admin + unless current_user.admin? + flash[:alert] = "Not allow!" + redirect_to root_path + end + end end diff --git a/app/controllers/admin/tweets_controller.rb b/app/controllers/admin/tweets_controller.rb index d489598b0..578e30573 100644 --- a/app/controllers/admin/tweets_controller.rb +++ b/app/controllers/admin/tweets_controller.rb @@ -1,13 +1,11 @@ class Admin::TweetsController < Admin::BaseController - before_action :authenticate_user! - def index @tweets = Tweet.order(created_at: :desc) end def destroy tweet = Tweet.find(params[:id]) - tweet.destroyed + tweet.destroy flash[:alert] = "tweets delete!" redirect_to admin_root_path end diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 3ba9f0a36..d22aa7d89 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -1,4 +1,5 @@ class Admin::UsersController < Admin::BaseController def index + @users = User.order(tweets_count: :desc) end end diff --git a/app/views/admin/tweets/index.html.erb b/app/views/admin/tweets/index.html.erb index 55c3a949b..ef0d2f2ef 100644 --- a/app/views/admin/tweets/index.html.erb +++ b/app/views/admin/tweets/index.html.erb @@ -1 +1,31 @@ -

    tweets back

    \ No newline at end of file +
    +

    Tweet後台 <%= link_to 'User List', admin_users_path, class: "btn btn-default" %>

    +
    +
    + + + + + + + + + + + <% @tweets.each do |tweet| %> + + + + + + + <% end %> + +
    NameTweetsAll RepliesDelete
    <%= tweet.user.name %><%= tweet.description %><% tweet.replies.each do |reply| %> + [<%= reply.comment %>]
    + <% end %>
    + <%= link_to 'Delete', admin_tweet_path(tweet), method: :delete, data: { confirm: "Are you sure?"} %> +
    +
    +
    +
    \ No newline at end of file diff --git a/app/views/admin/users/index.html.erb b/app/views/admin/users/index.html.erb new file mode 100644 index 000000000..37e94d0e3 --- /dev/null +++ b/app/views/admin/users/index.html.erb @@ -0,0 +1,29 @@ +
    +

    User List <%= link_to 'Tweet後台', admin_root_path, class: "btn btn-default" %>

    +
    +
    + + + + + + + + + + + + <% @users.each do |user| %> + + + + + + + + <% end %> + +
    Name推播數量關注人數跟隨者人數like 過的推播數
    <%= user.name %><%= user.tweets.count %><%= user.followings.count %><%= user.followers.count %><%= user.liked_tweets.count %>
    +
    +
    +
    \ No newline at end of file From 5d31a3cb6ba0f54c18bf5ae7b0a5c2c83a1c1697 Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Mon, 30 Jul 2018 15:26:28 +0800 Subject: [PATCH 27/32] final test 3 failures --- app/models/reply.rb | 4 ---- app/views/layouts/application.html.erb | 6 +++--- app/views/replies/index.html.erb | 2 +- app/views/shared/_user_intro.html.erb | 10 +++++----- app/views/tweets/index.html.erb | 4 ++-- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/app/models/reply.rb b/app/models/reply.rb index 74a2ded36..c7f16d932 100644 --- a/app/models/reply.rb +++ b/app/models/reply.rb @@ -1,9 +1,5 @@ class Reply < ApplicationRecord - validates_presence_of :comment - belongs_to :user belongs_to :tweet, counter_cache: true - - end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 938ca69ff..d19dcf44f 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -19,16 +19,16 @@ -

    <%= link_to 'EZ twitter', root_path %>

    +

    <%= link_to '簡易推特', root_path %>

    - <%= f.submit "Reply"%> + <%= f.submit "Reply", class: "btn btn-primary movebtn" %>
    <% end %> diff --git a/app/views/shared/_user_intro.html.erb b/app/views/shared/_user_intro.html.erb index b0d748658..a1c55bdfd 100644 --- a/app/views/shared/_user_intro.html.erb +++ b/app/views/shared/_user_intro.html.erb @@ -3,22 +3,22 @@

    <%= @user.name %>

    <%= simple_format @user.introduction, style: "color:#4682B4" %>

    <%= link_to tweets_user_path(@user), class: "twuser" do %> - Tweets + Tweets <%= @tweets.count %> <% end %>

    <%= link_to followings_user_path(@user), class: "twuser" do %> - Following + Following <%= @followings.count %> <% end %>

    <%= link_to followers_user_path(@user), class: "twuser" do %> - Follower + Follower <%= @followers.count %> <% end %>

    <%= link_to likes_user_path(@user), class: "twuser" do %> - Like + Like <%= @likes.count %> <% end %>

    <% if @user.email == current_user.email %> <%= link_to 'Edit Profile', edit_user_path(@user), class: "btn btn-primary" %> - + <%else %> <% if @user.following?(current_user)%> <%= link_to 'Unfollow', followship_path(@user), method: :delete, class: "btn btn-primary" %> <% else %> diff --git a/app/views/tweets/index.html.erb b/app/views/tweets/index.html.erb index 2a62fea05..95fac5e93 100644 --- a/app/views/tweets/index.html.erb +++ b/app/views/tweets/index.html.erb @@ -7,7 +7,7 @@ <%= f.text_area :description, placeholder: "你想說什麼?", class: "form-control", rows: "10" %>
    - <%= f.submit "推吧推吧", class: "btn btn-primary movebtn" %> + <%= f.submit "推吧", class: "btn btn-primary movebtn" %>
    <% end %> @@ -40,7 +40,7 @@
    -

    Popular

    +

    熱門玩家

    <% @users.each do |user| %>
    <%= image_tag (user.avatar), class: "usertweet-avatar" %> From bd208ecbf4222d134988776a4bccd1f2b0bd19f1 Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Mon, 30 Jul 2018 16:29:56 +0800 Subject: [PATCH 28/32] autotest complete --- app/controllers/replies_controller.rb | 6 +++--- app/views/replies/index.html.erb | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/controllers/replies_controller.rb b/app/controllers/replies_controller.rb index 308fd11ab..2c8757986 100644 --- a/app/controllers/replies_controller.rb +++ b/app/controllers/replies_controller.rb @@ -6,9 +6,9 @@ def index @replies = @tweet.replies @user = @tweet.user @tweets = @user.tweets - #@followings = @user.followings - #@followers = @user.followers - #@likes = @user.likes + @followings = @user.followings + @followers = @user.followers + @likes = @user.likes end def create diff --git a/app/views/replies/index.html.erb b/app/views/replies/index.html.erb index f3dfd46da..a131dec94 100644 --- a/app/views/replies/index.html.erb +++ b/app/views/replies/index.html.erb @@ -11,11 +11,9 @@ <%= simple_format @tweet.description, style: "color:#808080" %> <%= link_to tweet_replies_path(@tweet) do %> - Reply + Reply (<%= @tweet.replies_count %>) <% end %> - -

    Replies

    <% @replies.each do |reply| %> From cce152782d8c890563f4c2ead18411058a31a2ed Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Tue, 31 Jul 2018 15:00:23 +0800 Subject: [PATCH 29/32] a little move login view --- app/views/devise/sessions/new.html.erb | 5 ++++- app/views/tweets/index.html.erb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index 3ebb001d1..7e03e09db 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -1,4 +1,5 @@ -

    Log in

    +
    +

    登入

    <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
    @@ -24,3 +25,5 @@ <% end %> <%= render "devise/shared/links" %> + +
    diff --git a/app/views/tweets/index.html.erb b/app/views/tweets/index.html.erb index 95fac5e93..929f9cbfb 100644 --- a/app/views/tweets/index.html.erb +++ b/app/views/tweets/index.html.erb @@ -22,7 +22,7 @@
    <%= link_to tweet.user.name, tweets_user_path(tweet.user) %>,<%= tweet.created_at.to_date %>,<%= tweet.created_at.strftime("%k:%M") %>
    <%= simple_format tweet.description, style: "color:#808080" %> <%= link_to tweet_replies_path(tweet) do %> - reply(<%= tweet.replies_count %>) + Reply(<%= tweet.replies_count %>) <% end %> <% if tweet.is_liked?(current_user) %> From 91633b058ecca148e21a808a47de4252c642e58b Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Tue, 31 Jul 2018 15:03:37 +0800 Subject: [PATCH 30/32] a little move login view2 --- app/views/devise/registrations/new.html.erb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index cecd79187..11ce92142 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -1,4 +1,6 @@ -

    Sign up

    +
    + +

    註冊

    <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> <%= devise_error_messages! %> @@ -31,6 +33,9 @@
    <%= f.submit "Sign up" %>
    -<% end %> -<%= render "devise/shared/links" %> + <% end %> + + <%= render "devise/shared/links" %> + +
    \ No newline at end of file From e78644bd1ca6886903b79cfc551905d34b75670a Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Tue, 31 Jul 2018 15:10:51 +0800 Subject: [PATCH 31/32] heroku setting --- config/database.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/database.yml b/config/database.yml index 0d02f2498..1c8d40f2a 100644 --- a/config/database.yml +++ b/config/database.yml @@ -21,5 +21,5 @@ test: database: db/test.sqlite3 production: - <<: *default - database: db/production.sqlite3 + adapter: postgresql + encoding: Unicode From bbd96e254b2c9e07aafb080d3d99c30a0a3d50be Mon Sep 17 00:00:00 2001 From: Kafka Tzeng Date: Tue, 31 Jul 2018 15:30:23 +0800 Subject: [PATCH 32/32] setting heroku gem --- Gemfile | 9 ++++++++- Gemfile.lock | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index e4d478e2b..34950007a 100644 --- a/Gemfile +++ b/Gemfile @@ -17,7 +17,7 @@ gem 'ffaker' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.1.4' # Use sqlite3 as the database for Active Record -gem 'sqlite3' + # Use Puma as the app server gem 'puma', '~> 3.7' # Use SCSS for stylesheets @@ -53,6 +53,7 @@ group :development, :test do gem 'factory_bot_rails' gem 'shoulda-matchers', '~> 3.1' gem 'rails-controller-testing' + gem 'sqlite3' end group :development do @@ -66,3 +67,9 @@ end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] + +group :production do + gem 'pg', '~> 0.20' +end + + diff --git a/Gemfile.lock b/Gemfile.lock index 29d8a4e5c..007b15f85 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -133,6 +133,9 @@ GEM nokogiri (1.8.1-x86-mingw32) mini_portile2 (~> 2.3.0) orm_adapter (0.5.0) + pg (0.21.0) + pg (0.21.0-x64-mingw32) + pg (0.21.0-x86-mingw32) public_suffix (3.0.1) puma (3.11.2) puma (3.11.2-java) @@ -271,6 +274,7 @@ DEPENDENCIES jbuilder (~> 2.5) jquery-rails listen (>= 3.0.5, < 3.2) + pg (~> 0.20) puma (~> 3.7) rails (~> 5.1.4) rails-controller-testing