Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 8 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ gem 'devise'
gem 'carrierwave'
# resize image size
# gem 'mini_magick'

gem 'kaminari'
gem 'ffaker'
gem 'jquery-rails'
gem 'bootstrap-sass', '~> 3.3.7'

# 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
Expand Down Expand Up @@ -60,6 +62,10 @@ group :development do
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'sqlite3'
end
group :production do
gem 'pg', '~> 0.20'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
Expand Down
30 changes: 29 additions & 1 deletion 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.2)
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,7 +284,10 @@ 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
Expand All @@ -276,4 +304,4 @@ DEPENDENCIES
web-console (>= 3.3.0)

BUNDLED WITH
1.16.1
1.16.3
3 changes: 0 additions & 3 deletions app/assets/config/manifest.js

This file was deleted.

3 changes: 3 additions & 0 deletions app/assets/javascripts/admin/replies.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
2 changes: 2 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
//= require rails-ujs
//= require turbolinks
//= require_tree .
//= require jquery
//= require bootstrap-sprockets
3 changes: 3 additions & 0 deletions app/assets/stylesheets/admin/replies.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the admin::replies controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
2 changes: 1 addition & 1 deletion app/assets/stylesheets/admin/tweets.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Place all the styles related to the admin/tweets controller here.
// Place all the styles related to the admin::tweets controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
2 changes: 1 addition & 1 deletion app/assets/stylesheets/admin/users.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Place all the styles related to the admin/users controller here.
// Place all the styles related to the admin::users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
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";

76 changes: 76 additions & 0 deletions app/assets/stylesheets/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
.nav-pills-center {
text-align: center;
}

.nav-pills-center > li {
float: none;
display: inline-block;
}


.panel-body{
text-align: center;
}

.avatar{
height: 300px;
float: left;
width: 28%;
margin-right: 20px;
}
.edit_form{
float: left;
width: 68%;
}
.avatar img{
height: 200px;
width: 150px;
display: block;
}

.nav-tabs{
margin-bottom: 20px;
}
.restaurant_feed{
width: 48%;
float: left;
margin-right: 2%;
}
.panel-default {
padding: 5px;
}
.user-item {
margin-bottom: 20px;
}
.tweet {
border: 1px solid;
padding:10px;
margin-top: 30px;
margin-bottom: 30px;
}
.information {
width: 68%;
float: left;
margin-right: 20px;
}
.popular{
width: 28%;
float: left;
}
.tweet-avatar{
float: left;
margin: 0.5%;
margin-right: 15px;
margin-bottom: 15px;
}
.form_group{
margin-top: 5px;
}
.about{
width: 28%;
float: left;
}
.content{
width: 68%;
float: left;
}
1 change: 1 addition & 0 deletions app/controllers/admin/base_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class Admin::BaseController < ApplicationController


end
21 changes: 21 additions & 0 deletions app/controllers/admin/replies_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Admin::RepliesController < ApplicationController
def index
@replies = Reply.order(created_at: :desc)
@tweet = Tweet.find(params[:tweet_id])
if current_user.admin? == false
redirect_to root_path
end

end


def destroy
@tweet= Tweet.find(params[:tweet_id])
@reply = Reply.find(params[:id])

if current_user.admin?
@reply.destroy
redirect_to admin_tweet_replies_path(@tweet)
end
end
end
15 changes: 14 additions & 1 deletion app/controllers/admin/tweets_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
class Admin::TweetsController < Admin::BaseController
def index
if current_user.admin? == false
redirect_to root_path
end
@tweets = Tweet.order(created_at: :desc)
end

def destroy
@tweet = Tweet.find(params[:id])
if current_user.admin?
@tweet.destroy
redirect_to admin_root_path
end
flash[:alert] = "tweet was deleted"
end



end
12 changes: 9 additions & 3 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
class Admin::UsersController < Admin::BaseController
def index
end
class Admin::UsersController < ApplicationController
def index
@users = User.order(tweets_count: :desc)
if current_user.admin? == false
redirect_to root_path
end

end

end
11 changes: 11 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
class ApplicationController < ActionController::Base
before_action :authenticate_user!
protect_from_forgery with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?



# 請參考 Devise 文件自訂表單後通過 Strong Parameters 的方法
# https://github.com/plataformatec/devise#strong-parameters
# 注意有 sign_up 和 account_update 兩種參數要處理

protected

def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
devise_parameter_sanitizer.permit(:account_update, keys: [:name])
end
end
23 changes: 22 additions & 1 deletion app/controllers/followships_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
class FollowshipsController < ApplicationController
def create
end
@user = User.find(params[:following_id])
if @user == current_user
flash[:notice] = "Can't follow self!"
redirect_back(fallback_location: 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)
#複數寫法
# @followship = current_user.followships.where(following_id: params[:id])
# @followship.destroy_all
end
end
28 changes: 24 additions & 4 deletions app/controllers/replies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
class RepliesController < ApplicationController
def index
@replies = Reply.all
@tweet = Tweet.find(params[:tweet_id])
@reply = Reply.new
end
def create
@tweet= Tweet.find(params[:tweet_id])
@reply= @tweet.replies.build(reply_params)
@reply.user= current_user
@reply.save!
redirect_to tweet_replies_path(@tweet)
end

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

def create
end
if current_user.admin?
@reply.destroy
redirect_to tweets_user_path(user)
end
end

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