Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
56a5f0f
add tweets index action and view for public users
freefish0308 Jul 19, 2018
d18831d
add tweets index action and view for admin
freefish0308 Jul 25, 2018
cc279bc
add login process and update view with login messages
freefish0308 Jul 25, 2018
20c9011
can log in but admin not yet
freefish0308 Jul 25, 2018
05ee85b
add user_profile name
freefish0308 Jul 25, 2018
47c81db
controller/admin/index action & destroy action
freefish0308 Jul 25, 2018
f3656c4
set tweets route index&create
freefish0308 Jul 25, 2018
c987061
add tweet create action and view
freefish0308 Jul 25, 2018
0ec7529
tweet can actually created
freefish0308 Jul 26, 2018
44e5747
set model and routes
freefish0308 Jul 26, 2018
3fd954e
create reply model and setup relation between restaurant, user and reply
freefish0308 Jul 26, 2018
e95f437
setup routes
freefish0308 Jul 26, 2018
ed553d6
profit#edit and page
freefish0308 Jul 28, 2018
fe63107
profit#create and set bootstrap
freefish0308 Jul 28, 2018
413f32f
reply_controller and view
freefish0308 Jul 28, 2018
33f18f5
reply success
freefish0308 Jul 28, 2018
6ed97c0
bootstrap setting
freefish0308 Jul 28, 2018
4466747
reply OK,now proceed follow action
freefish0308 Jul 29, 2018
05067b8
definte following? action
freefish0308 Jul 29, 2018
0bfb0a1
fix bootstarp and root_index view and like action
freefish0308 Jul 29, 2018
ce968a1
Like/Unlike action
freefish0308 Jul 29, 2018
c612df2
routes and root fix
freefish0308 Jul 30, 2018
60b2f00
Index_Popular
freefish0308 Jul 30, 2018
d824bc3
index/popular and count action
freefish0308 Jul 30, 2018
27100d9
profix's three path OK
freefish0308 Jul 30, 2018
88a1a1c
admin page OK
freefish0308 Jul 30, 2018
5d31a3c
final test 3 failures
freefish0308 Jul 30, 2018
bd208ec
autotest complete
freefish0308 Jul 30, 2018
cce1527
a little move login view
freefish0308 Jul 31, 2018
91633b0
a little move login view2
freefish0308 Jul 31, 2018
e78644b
heroku setting
freefish0308 Jul 31, 2018
bbd96e2
setting heroku gem
freefish0308 Jul 31, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ 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
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
Expand Down Expand Up @@ -51,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
Expand All @@ -64,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


15 changes: 15 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -124,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)
Expand Down Expand Up @@ -251,6 +263,7 @@ PLATFORMS
x86-mswin32

DEPENDENCIES
bootstrap-sass (~> 3.3.7)
byebug
capybara (~> 2.13)
carrierwave
Expand All @@ -259,7 +272,9 @@ DEPENDENCIES
factory_bot_rails
ffaker
jbuilder (~> 2.5)
jquery-rails
listen (>= 3.0.5, < 3.2)
pg (~> 0.20)
puma (~> 3.7)
rails (~> 5.1.4)
rails-controller-testing
Expand Down
4 changes: 3 additions & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
//
//= require rails-ujs
//= require turbolinks
//= require_tree .
//= require jquery
//= require bootstrap-sprockets
//= require_tree .
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* 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";
@import "style";
65 changes: 65 additions & 0 deletions app/assets/stylesheets/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
.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: 160px;
}

.twuser{
color:#666666;
}

h2{
color:#008B8B;
}

h5{
color:#4682B4;
}

h3{
color:#4682B4;
}

.movebtn{
float: right;
}

.twnavbar{
background-color:#ADD8E6;
}


.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;
}
10 changes: 9 additions & 1 deletion app/controllers/admin/base_controller.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions app/controllers/admin/tweets_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
class Admin::TweetsController < Admin::BaseController
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
1 change: 1 addition & 0 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Admin::UsersController < Admin::BaseController
def index
@users = User.order(tweets_count: :desc)
end
end
12 changes: 10 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +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 兩種參數要處理
end

protected

def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
devise_parameter_sanitizer.permit(:account_update, keys: [:name])
end
end
19 changes: 19 additions & 0 deletions app/controllers/followships_controller.rb
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions app/controllers/replies_controller.rb
Original file line number Diff line number Diff line change
@@ -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
31 changes: 30 additions & 1 deletion app/controllers/tweets_controller.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,45 @@
class TweetsController < ApplicationController


def index
@users # 基於測試規格,必須講定變數名稱,請用此變數中存放關注人數 Top 10 的使用者資料
@tweets = Tweet.order(created_at: :desc)
@tweet = Tweet.new
@users = User.order(followers_count: :desc).includes(:followers).limit(10)
# 基於測試規格,必須講定變數名稱,請用此變數中存放關注人數 Top 10 的使用者資料
end

def create
@tweet = Tweet.new(tweet_params)
@tweet.user = current_user
if @tweet.save
flash[:notice] = "推播建立!"
redirect_to :tweets
else
flash.now[:alert] = "推播不可空白!"
render :index
end

end


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



private
def tweet_params
params.require(:tweet).permit(:description)
end

end
43 changes: 40 additions & 3 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,61 @@
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)
@followings = @user.followings
@followers = @user.followers
@likes = @user.likes

end

def edit
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
@user = User.find(params[:id])
end

def user_params
params.require(:user).permit(:name, :introduction, :avatar)
end


end
Loading