Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
613c6eb
add twitter index action and view for admin
henryhsu0325 Jul 17, 2018
51e95c6
add validates uniqueness of name and email
henryhsu0325 Jul 17, 2018
165f4dd
install bootstrap-sass, jquery-rails, and change navbar
henryhsu0325 Jul 18, 2018
6559031
steup Heroku
henryhsu0325 Jul 18, 2018
6faf1c5
Test
henryhsu0325 Jul 18, 2018
8edbd45
Test for Admin
henryhsu0325 Jul 18, 2018
0f69b71
user can edit/update the profile details
henryhsu0325 Jul 18, 2018
c34a755
user can edit profile
henryhsu0325 Jul 18, 2018
79da53f
complete twitter index for public users
henryhsu0325 Jul 18, 2018
e72edf0
add rails dev:fake_tweet
henryhsu0325 Jul 19, 2018
bd57441
add pagination using Kaminari gem
henryhsu0325 Jul 20, 2018
11f3f2e
add config route
henryhsu0325 Jul 20, 2018
ee8e421
set tweet model/controller(依時間排序的顯示&限140字)
henryhsu0325 Jul 20, 2018
1be127c
add tweet index page
henryhsu0325 Jul 20, 2018
2b93f6c
setup relation among user,tweet and reply
henryhsu0325 Jul 20, 2018
bffd69a
add twitter index and some reply fuction
henryhsu0325 Jul 23, 2018
20f4a37
update profile
henryhsu0325 Jul 23, 2018
c872987
create user index page for admin
henryhsu0325 Jul 23, 2018
58ac26a
create tweet index page for admin
henryhsu0325 Jul 23, 2018
86ea870
setup relation among user,tweet and like
henryhsu0325 Jul 24, 2018
e93ac76
add like/unlike button & add tweets counnt on user model
henryhsu0325 Jul 24, 2018
07a77e9
setup relation between user and followship
henryhsu0325 Jul 24, 2018
d4437f4
user can view top10 followers on ranking page
henryhsu0325 Jul 24, 2018
cac48d7
Test
henryhsu0325 Jul 25, 2018
aa104c6
can't write unknown attribute
henryhsu0325 Jul 25, 2018
93aea92
update replies index page
henryhsu0325 Jul 25, 2018
76d76a8
fixed reply model
henryhsu0325 Jul 25, 2018
640f0f2
styled tweet index page
henryhsu0325 Jul 25, 2018
c1d80fd
add create & destroy action for followship record
henryhsu0325 Jul 25, 2018
aff601e
styled user edit page and reply index
henryhsu0325 Jul 25, 2018
0f159bf
styled tweet and reply index page
henryhsu0325 Jul 26, 2018
d721007
update tweet/user index page for admin
henryhsu0325 Jul 26, 2018
535c5c7
add user index fuction
henryhsu0325 Jul 26, 2018
b3340a6
update tweet index page for user
henryhsu0325 Jul 27, 2018
9b311e7
styled tweet & reply index page
henryhsu0325 Jul 27, 2018
1c0f4e6
create fake like data
henryhsu0325 Jul 27, 2018
3fb83a0
create fake followship data
henryhsu0325 Jul 27, 2018
a4f3d05
create like index page for user & update like/unlike button
henryhsu0325 Jul 27, 2018
b1aa4bc
styled like & tweet index page
henryhsu0325 Jul 27, 2018
a5fc40f
update like index for user
henryhsu0325 Jul 27, 2018
638617f
create following/follower index page for user
henryhsu0325 Jul 30, 2018
587796a
add reply index page fuction
henryhsu0325 Jul 30, 2018
7f4c4dd
add user avatar image in navbar
henryhsu0325 Jul 30, 2018
50a5b93
update edit user page, user page for admin, reply/like index page,and…
henryhsu0325 Jul 31, 2018
dd25149
update reply & edit user page button
henryhsu0325 Jul 31, 2018
81579ce
update follow page & styled
henryhsu0325 Jul 31, 2018
bb39bae
styled and update tweet/reply index page
henryhsu0325 Jul 31, 2018
5edf908
fixed tweet/user controller and followship model
henryhsu0325 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
13 changes: 10 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ 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 'sass-rails', '~> 5.0'
gem 'bootstrap-sass', '~> 3.3.7'
gem 'sass-rails', '>= 3.2'
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 All @@ -41,7 +41,14 @@ gem 'jbuilder', '~> 2.5'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

gem 'kaminari'

group :production do
gem 'pg', '~> 0.20'
end

group :development, :test do
gem 'sqlite3'
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
# Adds support for Capybara system testing and selenium driver
Expand Down
32 changes: 30 additions & 2 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,22 @@ 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)
kaminari (1.1.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.1.1)
kaminari-activerecord (= 1.1.1)
kaminari-core (= 1.1.1)
kaminari-actionview (1.1.1)
actionview
kaminari-core (= 1.1.1)
kaminari-activerecord (1.1.1)
activerecord
kaminari-core (= 1.1.1)
kaminari-core (1.1.1)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
Expand Down Expand Up @@ -124,6 +145,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 +275,7 @@ PLATFORMS
x86-mswin32

DEPENDENCIES
bootstrap-sass (~> 3.3.7)
byebug
capybara (~> 2.13)
carrierwave
Expand All @@ -259,12 +284,15 @@ DEPENDENCIES
factory_bot_rails
ffaker
jbuilder (~> 2.5)
jquery-rails
kaminari
listen (>= 3.0.5, < 3.2)
pg (~> 0.20)
puma (~> 3.7)
rails (~> 5.1.4)
rails-controller-testing
rspec-rails (~> 3.7)
sass-rails (~> 5.0)
sass-rails (>= 3.2)
selenium-webdriver
shoulda-matchers (~> 3.1)
spring
Expand All @@ -276,4 +304,4 @@ DEPENDENCIES
web-console (>= 3.3.0)

BUNDLED WITH
1.16.1
1.16.2
3 changes: 3 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
//
//= require rails-ujs
//= require turbolinks
//= require jquery
//= require bootstrap-sprockets
//= require_tree .

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* 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';
104 changes: 104 additions & 0 deletions app/assets/stylesheets/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
.navbar {
margin-bottom: 30px;
.img-1 {
padding: 0 10px;
}
img {
width: 50px;
height: 50px;
}
}

.form {
border: 3px solid #e3f2fd;
}

.info {
p {
color: #0a80d6;
font-size: 14px;
}
}

#index {
margin-bottom: 15px;
padding: 10px;
text-align: left;
float: left;

img {
padding: 6px;
width: 90px;
height: 90px;
}

p {
font-size: 14px;
}
}

.tweet {
border: 1px solid #bfbdbd;
border-radius: 10px;
margin-bottom: 10px;
padding: 10px;

p {
margin: 10px 0;
color: #7D7D7D;
}

img {
padding: 2px;
width: 100px;
height: 100px;
}

}

.reply {
border: 1px solid #bfbdbd;
padding: 5px;
margin-bottom: 10px;
}

.pop-user {
margin-bottom: 15px;
padding: 10px;
border: 1px solid #bfbdbd;
border-radius: 5px;

p {
color: #666464;
font-size: 14px;
}

a.name {
padding: 10px 0;
font-size: 16px;
font-weight: 800;
letter-spacing: 1px;

}

btn {
font-size: 14px;
}

img {
padding: 6px;
width: 90px;
height: 90px;
}

}

.like {
padding: 0 5px;
color: #f00;
}

.unlike {
padding: 0 5px;
color: #0f1;
}
12 changes: 11 additions & 1 deletion app/controllers/admin/base_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
class Admin::BaseController < ApplicationController
before_action :authenticate_admin

end
private

def authenticate_admin
unless current_user.admin?
flash[:alert] = "NOT ALLOW!"
redirect_to root_path
end
end

end
10 changes: 9 additions & 1 deletion app/controllers/admin/tweets_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
class Admin::TweetsController < Admin::BaseController
before_action :authenticate_user!
before_action :authenticate_admin

def index
@tweets = Tweet.all.order(created_at: :desc)
end

def destroy
@tweet = Tweet.find(params[:id])
@tweet.destroy
flash[:alert] = "Tweet was deleted!"
redirect_to admin_root_path
end
end
end
3 changes: 3 additions & 0 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
class Admin::UsersController < Admin::BaseController

def index
@users = User.order(tweets_count: :desc)
end

end
20 changes: 20 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,24 @@ class ApplicationController < ActionController::Base
# 請參考 Devise 文件自訂表單後通過 Strong Parameters 的方法
# https://github.com/plataformatec/devise#strong-parameters
# 注意有 sign_up 和 account_update 兩種參數要處理

before_action :authenticate_user!
before_action :configure_permitted_parameters, if: :devise_controller?


private

def authenticate_admin
unless current_user.admin?
flash[:alert] = "Not allow!"
redirect_to root_path
end
end

def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
end



end
16 changes: 15 additions & 1 deletion app/controllers/followships_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
class FollowshipsController < ApplicationController

def create
@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

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

end
15 changes: 14 additions & 1 deletion app/controllers/replies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
class RepliesController < ApplicationController

def index
@tweet = Tweet.find(params[:tweet_id])
@replies = @tweet.replies
@reply = Reply.new
end

def create
tweet = Tweet.find(params[:tweet_id])
reply = tweet.replies.create(reply_params)
reply.user = current_user
reply.save!
redirect_to tweet_replies_path(tweet)
end

end
private

def reply_params
params.require(:reply).permit(:comment)
end
end
Loading