From d5d587c9cf439e77679327bc58e6100b8200f687 Mon Sep 17 00:00:00 2001 From: Caven Date: Sun, 16 Jul 2017 14:51:19 +0800 Subject: [PATCH 1/4] install awesome_rails_console --- Gemfile | 2 ++ Gemfile.lock | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index e91c3ae..90a9d16 100644 --- a/Gemfile +++ b/Gemfile @@ -13,6 +13,8 @@ gem 'bootstrap-sass' gem 'devise' +gem 'awesome_rails_console' + # Use sqlite3 as the database for Active Record gem 'sqlite3' # Use Puma as the app server diff --git a/Gemfile.lock b/Gemfile.lock index 30c443b..8c99e2c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -41,6 +41,11 @@ GEM arel (7.1.4) autoprefixer-rails (6.7.6) execjs + awesome_print (1.8.0) + awesome_rails_console (0.4.0) + awesome_print + pry-rails + railties bcrypt (3.1.11) bindex (0.5.0) bootstrap-sass (3.3.7) @@ -48,6 +53,7 @@ GEM sass (>= 3.3.4) builder (3.2.3) byebug (9.0.6) + coderay (1.1.1) coffee-rails (4.2.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.2.x) @@ -96,6 +102,12 @@ GEM nokogiri (1.7.1) mini_portile2 (~> 2.1.0) orm_adapter (0.5.0) + pry (0.10.4) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + pry-rails (0.3.6) + pry (>= 0.10.4) puma (3.8.2) rack (2.0.1) rack-test (0.6.3) @@ -153,6 +165,7 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) + slop (3.6.0) spring (2.0.1) activesupport (>= 4.2) spring-watcher-listen (2.0.1) @@ -191,6 +204,7 @@ PLATFORMS ruby DEPENDENCIES + awesome_rails_console bootstrap-sass byebug coffee-rails (~> 4.2) @@ -212,4 +226,4 @@ DEPENDENCIES web-console (>= 3.3.0) BUNDLED WITH - 1.14.6 + 1.15.1 From 5e03a53a1519fd57c6947575847cf3274e730411 Mon Sep 17 00:00:00 2001 From: Caven Date: Sun, 16 Jul 2017 20:14:34 +0800 Subject: [PATCH 2/4] wrk --- Gemfile | 2 + Gemfile.lock | 3 ++ app/controllers/application_controller.rb | 2 +- app/controllers/users_controller.rb | 2 +- app/helpers/users_helper.rb | 7 ++- app/views/events/show.html.erb | 6 +-- config/application.rb | 3 +- config/initializers/development.sqlite3 | Bin 0 -> 8617984 bytes config/initializers/rack-attack.rb | 59 ++++++++++++++++++++++ config/routes.rb | 2 +- 10 files changed, 77 insertions(+), 9 deletions(-) create mode 100644 config/initializers/development.sqlite3 create mode 100644 config/initializers/rack-attack.rb diff --git a/Gemfile b/Gemfile index 90a9d16..22e3569 100644 --- a/Gemfile +++ b/Gemfile @@ -15,6 +15,8 @@ gem 'devise' gem 'awesome_rails_console' +gem 'rack-attack' + # Use sqlite3 as the database for Active Record gem 'sqlite3' # Use Puma as the app server diff --git a/Gemfile.lock b/Gemfile.lock index 8c99e2c..0fbef3c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -110,6 +110,8 @@ GEM pry (>= 0.10.4) puma (3.8.2) rack (2.0.1) + rack-attack (5.0.1) + rack rack-test (0.6.3) rack (>= 1.0) rails (5.0.2) @@ -214,6 +216,7 @@ DEPENDENCIES jquery-rails listen (~> 3.0.5) puma (~> 3.0) + rack-attack rails (~> 5.0.2) rspec-rails sass-rails (~> 5.0) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 682a07d..cd6ea53 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,6 +1,6 @@ class ApplicationController < ActionController::Base - # protect_from_forgery with: :exception + protect_from_forgery with: :exception helper_method :current_cart diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f1d232d..fd6cac4 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -21,7 +21,7 @@ def update protected def user_params - params.require(:user).permit(:nickname, :role) + params.require(:user).permit(:nickname) end end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index ed49051..38effe3 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -7,9 +7,12 @@ def user_avatar_link(user) email_md5 = Digest::MD5.hexdigest(user.email) gravatar_url = "https://www.gravatar.com/avatar/#{email_md5}" - str = "" + # str = "".html_safe + # str.html_safe - str.html_safe + content_tag(:div, + link_to(image_tag(gravatar_url), user_path(user)) + " " + user.display_name , + class: "user-link") end end diff --git a/app/views/events/show.html.erb b/app/views/events/show.html.erb index 0e89067..253e728 100644 --- a/app/views/events/show.html.erb +++ b/app/views/events/show.html.erb @@ -22,14 +22,14 @@
- <%= raw comment.content %> + <%= sanitize comment.content %>