├── .gitignore ├── Gemfile ├── Gemfile.lock ├── README.md ├── README.rdoc ├── Rakefile ├── app ├── assets │ ├── images │ │ └── .keep │ ├── javascripts │ │ └── application.js │ └── stylesheets │ │ └── application.css ├── controllers │ ├── application_controller.rb │ ├── articles_controller.rb │ ├── comments_controller.rb │ ├── concerns │ │ └── .keep │ ├── favorites_controller.rb │ ├── follows_controller.rb │ ├── profiles_controller.rb │ ├── sessions_controller.rb │ ├── tags_controller.rb │ └── users_controller.rb ├── helpers │ └── application_helper.rb ├── mailers │ └── .keep ├── models │ ├── .keep │ ├── article.rb │ ├── comment.rb │ ├── concerns │ │ └── .keep │ ├── favorite.rb │ ├── follow.rb │ └── user.rb └── views │ ├── articles │ ├── _article.json.jbuilder │ ├── index.json.jbuilder │ └── show.json.jbuilder │ ├── comments │ ├── _comment.json.jbuilder │ ├── create.json.jbuilder │ └── index.json.jbuilder │ ├── devise │ ├── registrations │ │ └── create.json.jbuilder │ └── sessions │ │ └── create.json.jbuilder │ ├── layouts │ └── application.html.erb │ ├── profiles │ ├── _profile.json.jbuilder │ └── show.json.jbuilder │ └── users │ ├── _user.json.jbuilder │ └── show.json.jbuilder ├── bin ├── bundle ├── rails ├── rake ├── setup └── spring ├── config.ru ├── config ├── application.rb ├── boot.rb ├── database.yml ├── environment.rb ├── environments │ ├── development.rb │ ├── production.rb │ └── test.rb ├── initializers │ ├── assets.rb │ ├── backtrace_silencers.rb │ ├── cookies_serializer.rb │ ├── devise.rb │ ├── filter_parameter_logging.rb │ ├── inflections.rb │ ├── jbuilder.rb │ ├── mime_types.rb │ ├── session_store.rb │ └── wrap_parameters.rb ├── locales │ ├── devise.en.yml │ └── en.yml ├── routes.rb └── secrets.yml ├── db ├── migrate │ ├── 20160712045707_devise_create_users.rb │ ├── 20160712045739_add_profile_fields_to_users.rb │ ├── 20160712052128_create_articles.rb │ ├── 20160712054809_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb │ ├── 20160712054810_add_missing_unique_indices.acts_as_taggable_on_engine.rb │ ├── 20160712054811_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb │ ├── 20160712054812_add_missing_taggable_index.acts_as_taggable_on_engine.rb │ ├── 20160712054813_change_collation_for_tag_names.acts_as_taggable_on_engine.rb │ ├── 20160712055201_create_favorites.rb │ ├── 20160712061113_create_comments.rb │ └── 20160712061614_acts_as_follower_migration.rb ├── schema.rb └── seeds.rb ├── lib ├── assets │ └── .keep └── tasks │ └── .keep ├── log └── .keep ├── project-logo.png ├── public ├── 404.html ├── 422.html ├── 500.html ├── favicon.ico └── robots.txt ├── test ├── controllers │ └── .keep ├── fixtures │ ├── .keep │ ├── articles.yml │ ├── comments.yml │ ├── favorites.yml │ └── users.yml ├── helpers │ └── .keep ├── integration │ └── .keep ├── mailers │ └── .keep ├── models │ ├── .keep │ ├── article_test.rb │ ├── comment_test.rb │ ├── favorite_test.rb │ └── user_test.rb └── test_helper.rb └── vendor └── assets ├── javascripts └── .keep └── stylesheets └── .keep /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # Ignore the default SQLite database. 11 | /db/*.sqlite3 12 | /db/*.sqlite3-journal 13 | 14 | # Ignore all logfiles and tempfiles. 15 | /log/* 16 | !/log/.keep 17 | /tmp 18 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | 4 | # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 5 | gem 'rails', '4.2.6' 6 | # Use sqlite3 as the database for Active Record 7 | gem 'sqlite3' 8 | # Use SCSS for stylesheets 9 | gem 'sass-rails', '~> 5.0' 10 | # Use Uglifier as compressor for JavaScript assets 11 | gem 'uglifier', '>= 1.3.0' 12 | # Use CoffeeScript for .coffee assets and views 13 | gem 'coffee-rails', '~> 4.1.0' 14 | # See https://github.com/rails/execjs#readme for more supported runtimes 15 | # gem 'therubyracer', platforms: :ruby 16 | 17 | # Use jquery as the JavaScript library 18 | gem 'jquery-rails' 19 | # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks 20 | gem 'turbolinks' 21 | # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 22 | gem 'jbuilder', '~> 2.0' 23 | # bundle exec rake doc:rails generates the API under doc/api. 24 | gem 'sdoc', '~> 0.4.0', group: :doc 25 | 26 | gem 'acts-as-taggable-on', '~> 3.5.0' 27 | gem 'acts_as_follower', '~> 0.2.1' 28 | gem 'devise', '~> 4.2.0' 29 | gem 'jwt', '~> 1.5.4' 30 | gem 'rack-cors', '~> 0.4.0' 31 | gem 'puma' 32 | 33 | # Use ActiveModel has_secure_password 34 | # gem 'bcrypt', '~> 3.1.7' 35 | 36 | # Use Unicorn as the app server 37 | # gem 'unicorn' 38 | 39 | # Use Capistrano for deployment 40 | # gem 'capistrano-rails', group: :development 41 | 42 | group :development, :test do 43 | # Call 'byebug' anywhere in the code to stop execution and get a debugger console 44 | gem 'byebug' 45 | end 46 | 47 | group :development do 48 | # Access an IRB console on exception pages or by using <%= console %> in views 49 | gem 'web-console', '~> 2.0' 50 | 51 | # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 52 | gem 'spring' 53 | end 54 | 55 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actionmailer (4.2.6) 5 | actionpack (= 4.2.6) 6 | actionview (= 4.2.6) 7 | activejob (= 4.2.6) 8 | mail (~> 2.5, >= 2.5.4) 9 | rails-dom-testing (~> 1.0, >= 1.0.5) 10 | actionpack (4.2.6) 11 | actionview (= 4.2.6) 12 | activesupport (= 4.2.6) 13 | rack (~> 1.6) 14 | rack-test (~> 0.6.2) 15 | rails-dom-testing (~> 1.0, >= 1.0.5) 16 | rails-html-sanitizer (~> 1.0, >= 1.0.2) 17 | actionview (4.2.6) 18 | activesupport (= 4.2.6) 19 | builder (~> 3.1) 20 | erubis (~> 2.7.0) 21 | rails-dom-testing (~> 1.0, >= 1.0.5) 22 | rails-html-sanitizer (~> 1.0, >= 1.0.2) 23 | activejob (4.2.6) 24 | activesupport (= 4.2.6) 25 | globalid (>= 0.3.0) 26 | activemodel (4.2.6) 27 | activesupport (= 4.2.6) 28 | builder (~> 3.1) 29 | activerecord (4.2.6) 30 | activemodel (= 4.2.6) 31 | activesupport (= 4.2.6) 32 | arel (~> 6.0) 33 | activesupport (4.2.6) 34 | i18n (~> 0.7) 35 | json (~> 1.7, >= 1.7.7) 36 | minitest (~> 5.1) 37 | thread_safe (~> 0.3, >= 0.3.4) 38 | tzinfo (~> 1.1) 39 | acts-as-taggable-on (3.5.0) 40 | activerecord (>= 3.2, < 5) 41 | acts_as_follower (0.2.1) 42 | arel (6.0.3) 43 | bcrypt (3.1.11) 44 | binding_of_caller (0.7.2) 45 | debug_inspector (>= 0.0.1) 46 | builder (3.2.2) 47 | byebug (9.0.5) 48 | coffee-rails (4.1.1) 49 | coffee-script (>= 2.2.0) 50 | railties (>= 4.0.0, < 5.1.x) 51 | coffee-script (2.4.1) 52 | coffee-script-source 53 | execjs 54 | coffee-script-source (1.10.0) 55 | concurrent-ruby (1.0.2) 56 | debug_inspector (0.0.2) 57 | devise (4.2.0) 58 | bcrypt (~> 3.0) 59 | orm_adapter (~> 0.1) 60 | railties (>= 4.1.0, < 5.1) 61 | responders 62 | warden (~> 1.2.3) 63 | erubis (2.7.0) 64 | execjs (2.7.0) 65 | globalid (0.3.6) 66 | activesupport (>= 4.1.0) 67 | i18n (0.7.0) 68 | jbuilder (2.5.0) 69 | activesupport (>= 3.0.0, < 5.1) 70 | multi_json (~> 1.2) 71 | jquery-rails (4.1.1) 72 | rails-dom-testing (>= 1, < 3) 73 | railties (>= 4.2.0) 74 | thor (>= 0.14, < 2.0) 75 | json (1.8.3) 76 | jwt (1.5.4) 77 | loofah (2.0.3) 78 | nokogiri (>= 1.5.9) 79 | mail (2.6.4) 80 | mime-types (>= 1.16, < 4) 81 | mime-types (3.1) 82 | mime-types-data (~> 3.2015) 83 | mime-types-data (3.2016.0521) 84 | mini_portile2 (2.1.0) 85 | minitest (5.9.0) 86 | multi_json (1.12.1) 87 | nokogiri (1.6.8) 88 | mini_portile2 (~> 2.1.0) 89 | pkg-config (~> 1.1.7) 90 | orm_adapter (0.5.0) 91 | pkg-config (1.1.7) 92 | puma (3.4.0) 93 | rack (1.6.4) 94 | rack-cors (0.4.0) 95 | rack-test (0.6.3) 96 | rack (>= 1.0) 97 | rails (4.2.6) 98 | actionmailer (= 4.2.6) 99 | actionpack (= 4.2.6) 100 | actionview (= 4.2.6) 101 | activejob (= 4.2.6) 102 | activemodel (= 4.2.6) 103 | activerecord (= 4.2.6) 104 | activesupport (= 4.2.6) 105 | bundler (>= 1.3.0, < 2.0) 106 | railties (= 4.2.6) 107 | sprockets-rails 108 | rails-deprecated_sanitizer (1.0.3) 109 | activesupport (>= 4.2.0.alpha) 110 | rails-dom-testing (1.0.7) 111 | activesupport (>= 4.2.0.beta, < 5.0) 112 | nokogiri (~> 1.6.0) 113 | rails-deprecated_sanitizer (>= 1.0.1) 114 | rails-html-sanitizer (1.0.3) 115 | loofah (~> 2.0) 116 | railties (4.2.6) 117 | actionpack (= 4.2.6) 118 | activesupport (= 4.2.6) 119 | rake (>= 0.8.7) 120 | thor (>= 0.18.1, < 2.0) 121 | rake (11.2.2) 122 | rdoc (4.2.2) 123 | json (~> 1.4) 124 | responders (2.2.0) 125 | railties (>= 4.2.0, < 5.1) 126 | sass (3.4.22) 127 | sass-rails (5.0.5) 128 | railties (>= 4.0.0, < 6) 129 | sass (~> 3.1) 130 | sprockets (>= 2.8, < 4.0) 131 | sprockets-rails (>= 2.0, < 4.0) 132 | tilt (>= 1.1, < 3) 133 | sdoc (0.4.1) 134 | json (~> 1.7, >= 1.7.7) 135 | rdoc (~> 4.0) 136 | spring (1.7.2) 137 | sprockets (3.6.3) 138 | concurrent-ruby (~> 1.0) 139 | rack (> 1, < 3) 140 | sprockets-rails (3.1.1) 141 | actionpack (>= 4.0) 142 | activesupport (>= 4.0) 143 | sprockets (>= 3.0.0) 144 | sqlite3 (1.3.11) 145 | thor (0.19.1) 146 | thread_safe (0.3.5) 147 | tilt (2.0.5) 148 | turbolinks (5.0.0) 149 | turbolinks-source (~> 5) 150 | turbolinks-source (5.0.0) 151 | tzinfo (1.2.2) 152 | thread_safe (~> 0.1) 153 | uglifier (3.0.0) 154 | execjs (>= 0.3.0, < 3) 155 | warden (1.2.6) 156 | rack (>= 1.0) 157 | web-console (2.3.0) 158 | activemodel (>= 4.0) 159 | binding_of_caller (>= 0.7.2) 160 | railties (>= 4.0) 161 | sprockets-rails (>= 2.0, < 4.0) 162 | 163 | PLATFORMS 164 | ruby 165 | 166 | DEPENDENCIES 167 | acts-as-taggable-on (~> 3.5.0) 168 | acts_as_follower (~> 0.2.1) 169 | byebug 170 | coffee-rails (~> 4.1.0) 171 | devise (~> 4.2.0) 172 | jbuilder (~> 2.0) 173 | jquery-rails 174 | jwt (~> 1.5.4) 175 | puma 176 | rack-cors (~> 0.4.0) 177 | rails (= 4.2.6) 178 | sass-rails (~> 5.0) 179 | sdoc (~> 0.4.0) 180 | spring 181 | sqlite3 182 | turbolinks 183 | uglifier (>= 1.3.0) 184 | web-console (~> 2.0) 185 | 186 | BUNDLED WITH 187 | 1.10.6 188 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ![Rails Example App](project-logo.png) 2 | 3 | > Example Rails codebase that adheres to the [RealWorld](https://github.com/gothinkster/realworld-example-apps) API spec. 4 | 5 | This repo is functionality complete -- PRs and issues welcome! 6 | 7 | Check out the [rails-5.1 branch](https://github.com/gothinkster/rails-realworld-example-app/tree/rails-5.1) to see the updated code for Rails 5.1 8 | 9 | # Getting started 10 | 11 | To get the Rails server running locally: 12 | 13 | - Clone this repo 14 | - `bundle install` to install all req'd dependencies 15 | - `rake db:migrate` to make all database migrations 16 | - `rails s` to start the local server 17 | 18 | 19 | 20 | # Code Overview 21 | 22 | ## Dependencies 23 | 24 | - [acts_as_follower](https://github.com/tcocca/acts_as_follower) - For implementing followers/following 25 | - [acts_as_taggable](https://github.com/mbleigh/acts-as-taggable-on) - For implementing tagging functionality 26 | - [Devise](https://github.com/plataformatec/devise) - For implementing authentication 27 | - [Jbuilder](https://github.com/rails/jbuilder) - Default JSON rendering gem that ships with Rails, used for making reusable templates for JSON output. 28 | - [JWT](https://github.com/jwt/ruby-jwt) - For generating and validating JWTs for authentication 29 | 30 | ## Folders 31 | 32 | - `app/models` - Contains the database models for the application where we can define methods, validations, queries, and relations to other models. 33 | - `app/views` - Contains templates for generating the JSON output for the API 34 | - `app/controllers` - Contains the controllers where requests are routed to their actions, where we find and manipulate our models and return them for the views to render. 35 | - `config` - Contains configuration files for our Rails application and for our database, along with an `initializers` folder for scripts that get run on boot. 36 | - `db` - Contains the migrations needed to create our database schema. 37 | 38 | ## Configuration 39 | 40 | ### camelCase Payloads 41 | 42 | - [`config/initializers/jbuilder.rb`](https://github.com/gothinkster/rails-realworld-example-app/blob/master/config/initializers/jbuilder.rb) - Jbuilder configuration for camelCase output 43 | - [`app/controllers/application_controller.rb#underscore_params!`](https://github.com/gothinkster/rails-realworld-example-app/blob/master/app/controllers/application_controller.rb#L44) - Convert camelCase params into snake_case params 44 | 45 | ### null_session 46 | 47 | By default Ruby on Rails will throw an exception when a request doesn't contain a valid CSRF token. Since we're using JWT's to authenticate users instead of sessions, we can tell Rails to use an empty session instead of throwing an exception for requests by specifying `:null_session` in [app/controllers/application_controller.rb](https://github.com/gothinkster/rails-realworld-example-app/blob/master/app/controllers/application_controller.rb#L4). 48 | 49 | ### Authentication 50 | 51 | Requests are authenticated using the `Authorization` header with a valid JWT. The [application_controller.rb#authenticate_user!](https://github.com/gothinkster/rails-realworld-example-app/blob/master/app/controllers/application_controller.rb#L32) filter is used like the one provided by Devise, it will respond with a 401 status code if the request requires authentication that hasn't been provided. The [application_controller.rb#authenticate_user](https://github.com/gothinkster/rails-realworld-example-app/blob/master/app/controllers/application_controller.rb#L18) filter is called on every request to try and authenticate the `Authorization` header. It will only interrupt the request if a JWT is present and invalid. The user's id is then parsed from the JWT and stored in an instance variable called [`@current_user_id`](https://github.com/gothinkster/rails-realworld-example-app/blob/master/app/controllers/application_controller.rb#L24). `@current_user_id` can be used in any controller when we only need the user's id to save a trip to the database. Otherwise, we can call [`current_user`](https://github.com/gothinkster/rails-realworld-example-app/blob/master/app/controllers/application_controller.rb#L36) to fetch the authenticated user from the database. 52 | 53 | Devise only requires an email and password upon registration. To allow additional parameters on sign up, we use [application_controller#configure_permitted_parameters](https://github.com/gothinkster/rails-realworld-example-app/blob/master/app/controllers/application_controller.rb#L14) to allow additional parameters. 54 | 55 | -------------------------------------------------------------------------------- /README.rdoc: -------------------------------------------------------------------------------- 1 | == README 2 | 3 | This README would normally document whatever steps are necessary to get the 4 | application up and running. 5 | 6 | Things you may want to cover: 7 | 8 | * Ruby version 9 | 10 | * System dependencies 11 | 12 | * Configuration 13 | 14 | * Database creation 15 | 16 | * Database initialization 17 | 18 | * How to run the test suite 19 | 20 | * Services (job queues, cache servers, search engines, etc.) 21 | 22 | * Deployment instructions 23 | 24 | * ... 25 | 26 | 27 | Please feel free to use a different markup language if you do not plan to run 28 | rake doc:app. 29 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require File.expand_path('../config/application', __FILE__) 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /app/assets/images/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gothinkster/rails-realworld-example-app/a2ae4fff78b3337683cea988c023281dcb5551b9/app/assets/images/.keep -------------------------------------------------------------------------------- /app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // compiled file. 9 | // 10 | // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details 11 | // about supported directives. 12 | // 13 | //= require jquery 14 | //= require jquery_ujs 15 | //= require turbolinks 16 | //= require_tree . 17 | -------------------------------------------------------------------------------- /app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 | * compiled file so the styles you add here take precedence over styles defined in any styles 10 | * defined in the other CSS/SCSS files in this directory. It is generally better to create a new 11 | * file per style scope. 12 | * 13 | *= require_tree . 14 | *= require_self 15 | */ 16 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | # Prevent CSRF attacks by raising an exception. 3 | # For APIs, you may want to use :null_session instead. 4 | protect_from_forgery with: :null_session 5 | 6 | respond_to :json 7 | 8 | before_action :underscore_params! 9 | before_action :configure_permitted_parameters, if: :devise_controller? 10 | before_action :authenticate_user 11 | 12 | private 13 | 14 | def configure_permitted_parameters 15 | devise_parameter_sanitizer.permit(:sign_up, keys: [:username]) 16 | end 17 | 18 | def authenticate_user 19 | if request.headers['Authorization'].present? 20 | authenticate_or_request_with_http_token do |token| 21 | begin 22 | jwt_payload = JWT.decode(token, Rails.application.secrets.secret_key_base).first 23 | 24 | @current_user_id = jwt_payload['id'] 25 | rescue JWT::ExpiredSignature, JWT::VerificationError, JWT::DecodeError 26 | head :unauthorized 27 | end 28 | end 29 | end 30 | end 31 | 32 | def authenticate_user!(options = {}) 33 | head :unauthorized unless signed_in? 34 | end 35 | 36 | def current_user 37 | @current_user ||= super || User.find(@current_user_id) 38 | end 39 | 40 | def signed_in? 41 | @current_user_id.present? 42 | end 43 | 44 | def underscore_params! 45 | params.deep_transform_keys!(&:underscore) 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /app/controllers/articles_controller.rb: -------------------------------------------------------------------------------- 1 | class ArticlesController < ApplicationController 2 | before_action :authenticate_user!, except: [:index, :show] 3 | 4 | def index 5 | @articles = Article.all.includes(:user) 6 | 7 | @articles = @articles.tagged_with(params[:tag]) if params[:tag].present? 8 | @articles = @articles.authored_by(params[:author]) if params[:author].present? 9 | @articles = @articles.favorited_by(params[:favorited]) if params[:favorited].present? 10 | 11 | @articles_count = @articles.count 12 | 13 | @articles = @articles.order(created_at: :desc).offset(params[:offset] || 0).limit(params[:limit] || 20) 14 | end 15 | 16 | def feed 17 | @articles = Article.includes(:user).where(user: current_user.following_users) 18 | 19 | @articles_count = @articles.count 20 | 21 | @articles = @articles.order(created_at: :desc).offset(params[:offset] || 0).limit(params[:limit] || 20) 22 | 23 | render :index 24 | end 25 | 26 | def create 27 | @article = Article.new(article_params) 28 | @article.user = current_user 29 | 30 | if @article.save 31 | render :show 32 | else 33 | render json: { errors: @article.errors }, status: :unprocessable_entity 34 | end 35 | end 36 | 37 | def show 38 | @article = Article.find_by_slug!(params[:slug]) 39 | end 40 | 41 | def update 42 | @article = Article.find_by_slug!(params[:slug]) 43 | 44 | if @article.user_id == @current_user_id 45 | @article.update_attributes(article_params) 46 | 47 | render :show 48 | else 49 | render json: { errors: { article: ['not owned by user'] } }, status: :forbidden 50 | end 51 | end 52 | 53 | def destroy 54 | @article = Article.find_by_slug!(params[:slug]) 55 | 56 | if @article.user_id == @current_user_id 57 | @article.destroy 58 | 59 | render json: {} 60 | else 61 | render json: { errors: { article: ['not owned by user'] } }, status: :forbidden 62 | end 63 | end 64 | 65 | private 66 | 67 | def article_params 68 | params.require(:article).permit(:title, :body, :description, tag_list: []) 69 | end 70 | end 71 | -------------------------------------------------------------------------------- /app/controllers/comments_controller.rb: -------------------------------------------------------------------------------- 1 | class CommentsController < ApplicationController 2 | before_action :authenticate_user!, except: [:index] 3 | before_action :find_article! 4 | 5 | def index 6 | @comments = @article.comments.order(created_at: :desc) 7 | end 8 | 9 | def create 10 | @comment = @article.comments.new(comment_params) 11 | @comment.user = current_user 12 | 13 | render json: { errors: @comment.errors }, status: :unprocessable_entity unless @comment.save 14 | end 15 | 16 | def destroy 17 | @comment = @article.comments.find(params[:id]) 18 | 19 | if @comment.user_id == @current_user_id 20 | @comment.destroy 21 | render json: {} 22 | else 23 | render json: { errors: { comment: ['not owned by user'] } }, status: :forbidden 24 | end 25 | end 26 | 27 | private 28 | 29 | def comment_params 30 | params.require(:comment).permit(:body) 31 | end 32 | 33 | def find_article! 34 | @article = Article.find_by_slug!(params[:article_slug]) 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gothinkster/rails-realworld-example-app/a2ae4fff78b3337683cea988c023281dcb5551b9/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /app/controllers/favorites_controller.rb: -------------------------------------------------------------------------------- 1 | class FavoritesController < ApplicationController 2 | before_action :authenticate_user! 3 | before_action :find_article! 4 | 5 | def create 6 | current_user.favorite(@article) 7 | 8 | render 'articles/show' 9 | end 10 | 11 | def destroy 12 | current_user.unfavorite(@article) 13 | 14 | render 'articles/show' 15 | end 16 | 17 | private 18 | 19 | def find_article! 20 | @article = Article.find_by_slug!(params[:article_slug]) 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /app/controllers/follows_controller.rb: -------------------------------------------------------------------------------- 1 | class FollowsController < ApplicationController 2 | before_action :authenticate_user! 3 | 4 | def create 5 | @user = User.find_by_username!(params[:profile_username]) 6 | 7 | current_user.follow(@user) if current_user.id != @user.id 8 | 9 | render 'profiles/show' 10 | end 11 | 12 | def destroy 13 | @user = User.find_by_username!(params[:profile_username]) 14 | 15 | current_user.stop_following(@user) if current_user.id != @user.id 16 | 17 | render 'profiles/show' 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /app/controllers/profiles_controller.rb: -------------------------------------------------------------------------------- 1 | class ProfilesController < ApplicationController 2 | def show 3 | @user = User.find_by_username(params[:username]) 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /app/controllers/sessions_controller.rb: -------------------------------------------------------------------------------- 1 | class SessionsController < Devise::SessionsController 2 | def create 3 | user = User.find_by_email(sign_in_params[:email]) 4 | 5 | if user && user.valid_password?(sign_in_params[:password]) 6 | @current_user = user 7 | else 8 | render json: { errors: { 'email or password' => ['is invalid'] } }, status: :unprocessable_entity 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /app/controllers/tags_controller.rb: -------------------------------------------------------------------------------- 1 | class TagsController < ApplicationController 2 | def index 3 | render json: { tags: Article.tag_counts.most_used.map(&:name) } 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /app/controllers/users_controller.rb: -------------------------------------------------------------------------------- 1 | class UsersController < ApplicationController 2 | before_action :authenticate_user! 3 | 4 | def show 5 | end 6 | 7 | def update 8 | if current_user.update_attributes(user_params) 9 | render :show 10 | else 11 | render json: { errors: current_user.errors }, status: :unprocessable_entity 12 | end 13 | end 14 | 15 | private 16 | 17 | def user_params 18 | params.require(:user).permit(:username, :email, :password, :bio, :image) 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/mailers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gothinkster/rails-realworld-example-app/a2ae4fff78b3337683cea988c023281dcb5551b9/app/mailers/.keep -------------------------------------------------------------------------------- /app/models/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gothinkster/rails-realworld-example-app/a2ae4fff78b3337683cea988c023281dcb5551b9/app/models/.keep -------------------------------------------------------------------------------- /app/models/article.rb: -------------------------------------------------------------------------------- 1 | class Article < ActiveRecord::Base 2 | belongs_to :user 3 | has_many :favorites, dependent: :destroy 4 | has_many :comments, dependent: :destroy 5 | 6 | scope :authored_by, ->(username) { where(user: User.where(username: username)) } 7 | scope :favorited_by, -> (username) { joins(:favorites).where(favorites: { user: User.where(username: username) }) } 8 | 9 | acts_as_taggable 10 | 11 | validates :title, presence: true, allow_blank: false 12 | validates :body, presence: true, allow_blank: false 13 | validates :slug, uniqueness: true, exclusion: { in: ['feed'] } 14 | 15 | has_many :articles, dependent: :destroy 16 | 17 | before_validation do 18 | self.slug ||= "#{title.to_s.parameterize}-#{rand(36**6).to_s(36)}" 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /app/models/comment.rb: -------------------------------------------------------------------------------- 1 | class Comment < ActiveRecord::Base 2 | belongs_to :user 3 | belongs_to :article 4 | 5 | validates :body, presence: true, allow_blank: false 6 | end 7 | -------------------------------------------------------------------------------- /app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gothinkster/rails-realworld-example-app/a2ae4fff78b3337683cea988c023281dcb5551b9/app/models/concerns/.keep -------------------------------------------------------------------------------- /app/models/favorite.rb: -------------------------------------------------------------------------------- 1 | class Favorite < ActiveRecord::Base 2 | belongs_to :user 3 | belongs_to :article, counter_cache: true 4 | end 5 | -------------------------------------------------------------------------------- /app/models/follow.rb: -------------------------------------------------------------------------------- 1 | class Follow < ActiveRecord::Base 2 | 3 | extend ActsAsFollower::FollowerLib 4 | extend ActsAsFollower::FollowScopes 5 | 6 | # NOTE: Follows belong to the "followable" interface, and also to followers 7 | belongs_to :followable, polymorphic: true 8 | belongs_to :follower, polymorphic: true 9 | 10 | def block! 11 | self.update_attribute(:blocked, true) 12 | end 13 | 14 | end 15 | -------------------------------------------------------------------------------- /app/models/user.rb: -------------------------------------------------------------------------------- 1 | class User < ActiveRecord::Base 2 | # Include default devise modules. Others available are: 3 | # :confirmable, :lockable, :timeoutable and :omniauthable 4 | devise :database_authenticatable, :registerable, 5 | :recoverable, :rememberable, :trackable, :validatable 6 | 7 | has_many :articles, dependent: :destroy 8 | has_many :favorites, dependent: :destroy 9 | has_many :comments, dependent: :destroy 10 | 11 | acts_as_follower 12 | acts_as_followable 13 | 14 | 15 | validates :username, uniqueness: { case_sensitive: true }, 16 | format: { with: /\A[a-zA-Z0-9]+\z/ }, 17 | presence: true, 18 | allow_blank: false 19 | 20 | def generate_jwt 21 | JWT.encode({ id: id, 22 | exp: 60.days.from_now.to_i }, 23 | Rails.application.secrets.secret_key_base) 24 | end 25 | 26 | def favorite(article) 27 | favorites.find_or_create_by(article: article) 28 | end 29 | 30 | def unfavorite(article) 31 | favorites.where(article: article).destroy_all 32 | 33 | article.reload 34 | end 35 | 36 | def favorited?(article) 37 | favorites.find_by(article_id: article.id).present? 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /app/views/articles/_article.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.(article, :title, :slug, :body, :created_at, :updated_at, :description, :tag_list) 2 | json.author article.user, partial: 'profiles/profile', as: :user 3 | json.favorited signed_in? ? current_user.favorited?(article) : false 4 | json.favorites_count article.favorites_count || 0 5 | -------------------------------------------------------------------------------- /app/views/articles/index.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.articles do |json| 2 | json.array! @articles, partial: 'articles/article', as: :article 3 | end 4 | 5 | json.articles_count @articles_count 6 | -------------------------------------------------------------------------------- /app/views/articles/show.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.article do |json| 2 | json.partial! 'articles/article', article: @article 3 | end 4 | -------------------------------------------------------------------------------- /app/views/comments/_comment.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.(comment, :id, :created_at, :updated_at, :body) 2 | json.author comment.user, partial: 'profiles/profile', as: :user 3 | -------------------------------------------------------------------------------- /app/views/comments/create.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.comment do |json| 2 | json.partial! 'comments/comment', comment: @comment 3 | end 4 | -------------------------------------------------------------------------------- /app/views/comments/index.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.comments do |json| 2 | json.array! @comments, partial: 'comments/comment', as: :comment 3 | end 4 | -------------------------------------------------------------------------------- /app/views/devise/registrations/create.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.user do |json| 2 | json.partial! 'users/user', user: current_user 3 | end 4 | -------------------------------------------------------------------------------- /app/views/devise/sessions/create.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.user do |json| 2 | json.partial! 'users/user', user: current_user 3 | end 4 | -------------------------------------------------------------------------------- /app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Conduit 5 | <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> 6 | <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> 7 | <%= csrf_meta_tags %> 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /app/views/profiles/_profile.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.(user, :username, :bio) 2 | json.image user.image || 'https://static.productionready.io/images/smiley-cyrus.jpg' 3 | json.following signed_in? ? current_user.following?(user) : false 4 | -------------------------------------------------------------------------------- /app/views/profiles/show.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.profile do |json| 2 | json.partial! 'profiles/profile', user: @user 3 | end 4 | -------------------------------------------------------------------------------- /app/views/users/_user.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.(user, :id, :email, :username, :bio, :image) 2 | json.token user.generate_jwt 3 | -------------------------------------------------------------------------------- /app/views/users/show.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.user do |json| 2 | json.partial! 'users/user', user: current_user 3 | end 4 | -------------------------------------------------------------------------------- /bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | begin 3 | load File.expand_path('../spring', __FILE__) 4 | rescue LoadError => e 5 | raise unless e.message.include?('spring') 6 | end 7 | APP_PATH = File.expand_path('../../config/application', __FILE__) 8 | require_relative '../config/boot' 9 | require 'rails/commands' 10 | -------------------------------------------------------------------------------- /bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | begin 3 | load File.expand_path('../spring', __FILE__) 4 | rescue LoadError => e 5 | raise unless e.message.include?('spring') 6 | end 7 | require_relative '../config/boot' 8 | require 'rake' 9 | Rake.application.run 10 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'pathname' 3 | 4 | # path to your application root. 5 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) 6 | 7 | Dir.chdir APP_ROOT do 8 | # This script is a starting point to setup your application. 9 | # Add necessary setup steps to this file: 10 | 11 | puts "== Installing dependencies ==" 12 | system "gem install bundler --conservative" 13 | system "bundle check || bundle install" 14 | 15 | # puts "\n== Copying sample files ==" 16 | # unless File.exist?("config/database.yml") 17 | # system "cp config/database.yml.sample config/database.yml" 18 | # end 19 | 20 | puts "\n== Preparing database ==" 21 | system "bin/rake db:setup" 22 | 23 | puts "\n== Removing old logs and tempfiles ==" 24 | system "rm -f log/*" 25 | system "rm -rf tmp/cache" 26 | 27 | puts "\n== Restarting application server ==" 28 | system "touch tmp/restart.txt" 29 | end 30 | -------------------------------------------------------------------------------- /bin/spring: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # This file loads spring without using Bundler, in order to be fast. 4 | # It gets overwritten when you run the `spring binstub` command. 5 | 6 | unless defined?(Spring) 7 | require 'rubygems' 8 | require 'bundler' 9 | 10 | if (match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m)) 11 | Gem.paths = { 'GEM_PATH' => [Bundler.bundle_path.to_s, *Gem.path].uniq.join(Gem.path_separator) } 12 | gem 'spring', match[1] 13 | require 'spring/binstub' 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run Rails.application 5 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | require 'rails/all' 4 | 5 | # Require the gems listed in Gemfile, including any gems 6 | # you've limited to :test, :development, or :production. 7 | Bundler.require(*Rails.groups) 8 | 9 | module Conduit 10 | class Application < Rails::Application 11 | # Settings in config/environments/* take precedence over those specified here. 12 | # Application configuration should go into files in config/initializers 13 | # -- all .rb files in that directory are automatically loaded. 14 | 15 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 16 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 17 | # config.time_zone = 'Central Time (US & Canada)' 18 | 19 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 20 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 21 | # config.i18n.default_locale = :de 22 | 23 | # Do not swallow errors in after_commit/after_rollback callbacks. 24 | config.active_record.raise_in_transactional_callbacks = true 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 2 | 3 | require 'bundler/setup' # Set up gems listed in the Gemfile. 4 | -------------------------------------------------------------------------------- /config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite version 3.x 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem 'sqlite3' 6 | # 7 | default: &default 8 | adapter: sqlite3 9 | pool: 5 10 | timeout: 5000 11 | 12 | development: 13 | <<: *default 14 | database: db/development.sqlite3 15 | 16 | # Warning: The database defined as "test" will be erased and 17 | # re-generated from your development database when you run "rake". 18 | # Do not set this db to the same as development or production. 19 | test: 20 | <<: *default 21 | database: db/test.sqlite3 22 | 23 | production: 24 | <<: *default 25 | database: db/production.sqlite3 26 | -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Do not eager load code on boot. 10 | config.eager_load = false 11 | 12 | # Show full error reports and disable caching. 13 | config.consider_all_requests_local = true 14 | config.action_controller.perform_caching = false 15 | 16 | # Don't care if the mailer can't send. 17 | config.action_mailer.raise_delivery_errors = false 18 | 19 | # Print deprecation notices to the Rails logger. 20 | config.active_support.deprecation = :log 21 | 22 | # Raise an error on page load if there are pending migrations. 23 | config.active_record.migration_error = :page_load 24 | 25 | # Debug mode disables concatenation and preprocessing of assets. 26 | # This option may cause significant delays in view rendering with a large 27 | # number of complex assets. 28 | config.assets.debug = true 29 | 30 | # Asset digests allow you to set far-future HTTP expiration dates on all assets, 31 | # yet still be able to expire them through the digest params. 32 | config.assets.digest = true 33 | 34 | # Adds additional error checking when serving assets at runtime. 35 | # Checks for improperly declared sprockets dependencies. 36 | # Raises helpful error messages. 37 | config.assets.raise_runtime_errors = true 38 | 39 | # Raises error for missing translations 40 | # config.action_view.raise_on_missing_translations = true 41 | end 42 | -------------------------------------------------------------------------------- /config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # Code is not reloaded between requests. 5 | config.cache_classes = true 6 | 7 | # Eager load code on boot. This eager loads most of Rails and 8 | # your application in memory, allowing both threaded web servers 9 | # and those relying on copy on write to perform better. 10 | # Rake tasks automatically ignore this option for performance. 11 | config.eager_load = true 12 | 13 | # Full error reports are disabled and caching is turned on. 14 | config.consider_all_requests_local = false 15 | config.action_controller.perform_caching = true 16 | 17 | # Enable Rack::Cache to put a simple HTTP cache in front of your application 18 | # Add `rack-cache` to your Gemfile before enabling this. 19 | # For large-scale production use, consider using a caching reverse proxy like 20 | # NGINX, varnish or squid. 21 | # config.action_dispatch.rack_cache = true 22 | 23 | # Disable serving static files from the `/public` folder by default since 24 | # Apache or NGINX already handles this. 25 | config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? 26 | 27 | # Compress JavaScripts and CSS. 28 | config.assets.js_compressor = :uglifier 29 | # config.assets.css_compressor = :sass 30 | 31 | # Do not fallback to assets pipeline if a precompiled asset is missed. 32 | config.assets.compile = false 33 | 34 | # Asset digests allow you to set far-future HTTP expiration dates on all assets, 35 | # yet still be able to expire them through the digest params. 36 | config.assets.digest = true 37 | 38 | # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb 39 | 40 | # Specifies the header that your server uses for sending files. 41 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 42 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 43 | 44 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 45 | # config.force_ssl = true 46 | 47 | # Use the lowest log level to ensure availability of diagnostic information 48 | # when problems arise. 49 | config.log_level = :debug 50 | 51 | # Prepend all log lines with the following tags. 52 | # config.log_tags = [ :subdomain, :uuid ] 53 | 54 | # Use a different logger for distributed setups. 55 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) 56 | 57 | # Use a different cache store in production. 58 | # config.cache_store = :mem_cache_store 59 | 60 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 61 | # config.action_controller.asset_host = 'http://assets.example.com' 62 | 63 | # Ignore bad email addresses and do not raise email delivery errors. 64 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 65 | # config.action_mailer.raise_delivery_errors = false 66 | 67 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 68 | # the I18n.default_locale when a translation cannot be found). 69 | config.i18n.fallbacks = true 70 | 71 | # Send deprecation notices to registered listeners. 72 | config.active_support.deprecation = :notify 73 | 74 | # Use default logging formatter so that PID and timestamp are not suppressed. 75 | config.log_formatter = ::Logger::Formatter.new 76 | 77 | # Do not dump schema after migrations. 78 | config.active_record.dump_schema_after_migration = false 79 | end 80 | -------------------------------------------------------------------------------- /config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Do not eager load code on boot. This avoids loading your whole application 11 | # just for the purpose of running a single test. If you are using a tool that 12 | # preloads Rails for running tests, you may have to set it to true. 13 | config.eager_load = false 14 | 15 | # Configure static file server for tests with Cache-Control for performance. 16 | config.serve_static_files = true 17 | config.static_cache_control = 'public, max-age=3600' 18 | 19 | # Show full error reports and disable caching. 20 | config.consider_all_requests_local = true 21 | config.action_controller.perform_caching = false 22 | 23 | # Raise exceptions instead of rendering exception templates. 24 | config.action_dispatch.show_exceptions = false 25 | 26 | # Disable request forgery protection in test environment. 27 | config.action_controller.allow_forgery_protection = false 28 | 29 | # Tell Action Mailer not to deliver emails to the real world. 30 | # The :test delivery method accumulates sent emails in the 31 | # ActionMailer::Base.deliveries array. 32 | config.action_mailer.delivery_method = :test 33 | 34 | # Randomize the order test cases are executed. 35 | config.active_support.test_order = :random 36 | 37 | # Print deprecation notices to the stderr. 38 | config.active_support.deprecation = :stderr 39 | 40 | # Raises error for missing translations 41 | # config.action_view.raise_on_missing_translations = true 42 | end 43 | -------------------------------------------------------------------------------- /config/initializers/assets.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Version of your assets, change this if you want to expire all your assets. 4 | Rails.application.config.assets.version = '1.0' 5 | 6 | # Add additional assets to the asset load path 7 | # Rails.application.config.assets.paths << Emoji.images_path 8 | 9 | # Precompile additional assets. 10 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. 11 | # Rails.application.config.assets.precompile += %w( search.js ) 12 | -------------------------------------------------------------------------------- /config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /config/initializers/cookies_serializer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Rails.application.config.action_dispatch.cookies_serializer = :json 4 | -------------------------------------------------------------------------------- /config/initializers/devise.rb: -------------------------------------------------------------------------------- 1 | # Use this hook to configure devise mailer, warden hooks and so forth. 2 | # Many of these configuration options can be set straight in your model. 3 | Devise.setup do |config| 4 | # The secret key used by Devise. Devise uses this key to generate 5 | # random tokens. Changing this key will render invalid all existing 6 | # confirmation, reset password and unlock tokens in the database. 7 | # Devise will use the `secret_key_base` as its `secret_key` 8 | # by default. You can change it below and use your own secret key. 9 | # config.secret_key = 'b8008800973c064ef11a8e1a7477c983f7526dc8e44e45b7713c1e92ad8cb1095e1b280716e92d99e4c4dc32497230677617adec1a179ffdf114ed222e69c123' 10 | 11 | # ==> Mailer Configuration 12 | # Configure the e-mail address which will be shown in Devise::Mailer, 13 | # note that it will be overwritten if you use your own mailer class 14 | # with default "from" parameter. 15 | config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' 16 | 17 | # Configure the class responsible to send e-mails. 18 | # config.mailer = 'Devise::Mailer' 19 | 20 | # Configure the parent class responsible to send e-mails. 21 | # config.parent_mailer = 'ActionMailer::Base' 22 | 23 | # ==> ORM configuration 24 | # Load and configure the ORM. Supports :active_record (default) and 25 | # :mongoid (bson_ext recommended) by default. Other ORMs may be 26 | # available as additional gems. 27 | require 'devise/orm/active_record' 28 | 29 | # ==> Configuration for any authentication mechanism 30 | # Configure which keys are used when authenticating a user. The default is 31 | # just :email. You can configure it to use [:username, :subdomain], so for 32 | # authenticating a user, both parameters are required. Remember that those 33 | # parameters are used only when authenticating and not when retrieving from 34 | # session. If you need permissions, you should implement that in a before filter. 35 | # You can also supply a hash where the value is a boolean determining whether 36 | # or not authentication should be aborted when the value is not present. 37 | # config.authentication_keys = [:email] 38 | 39 | # Configure parameters from the request object used for authentication. Each entry 40 | # given should be a request method and it will automatically be passed to the 41 | # find_for_authentication method and considered in your model lookup. For instance, 42 | # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. 43 | # The same considerations mentioned for authentication_keys also apply to request_keys. 44 | # config.request_keys = [] 45 | 46 | # Configure which authentication keys should be case-insensitive. 47 | # These keys will be downcased upon creating or modifying a user and when used 48 | # to authenticate or find a user. Default is :email. 49 | config.case_insensitive_keys = [:email] 50 | 51 | # Configure which authentication keys should have whitespace stripped. 52 | # These keys will have whitespace before and after removed upon creating or 53 | # modifying a user and when used to authenticate or find a user. Default is :email. 54 | config.strip_whitespace_keys = [:email] 55 | 56 | # Tell if authentication through request.params is enabled. True by default. 57 | # It can be set to an array that will enable params authentication only for the 58 | # given strategies, for example, `config.params_authenticatable = [:database]` will 59 | # enable it only for database (email + password) authentication. 60 | # config.params_authenticatable = true 61 | 62 | # Tell if authentication through HTTP Auth is enabled. False by default. 63 | # It can be set to an array that will enable http authentication only for the 64 | # given strategies, for example, `config.http_authenticatable = [:database]` will 65 | # enable it only for database authentication. The supported strategies are: 66 | # :database = Support basic authentication with authentication key + password 67 | # config.http_authenticatable = false 68 | 69 | # If 401 status code should be returned for AJAX requests. True by default. 70 | # config.http_authenticatable_on_xhr = true 71 | 72 | # The realm used in Http Basic Authentication. 'Application' by default. 73 | # config.http_authentication_realm = 'Application' 74 | 75 | # It will change confirmation, password recovery and other workflows 76 | # to behave the same regardless if the e-mail provided was right or wrong. 77 | # Does not affect registerable. 78 | # config.paranoid = true 79 | 80 | # By default Devise will store the user in session. You can skip storage for 81 | # particular strategies by setting this option. 82 | # Notice that if you are skipping storage for all authentication paths, you 83 | # may want to disable generating routes to Devise's sessions controller by 84 | # passing skip: :sessions to `devise_for` in your config/routes.rb 85 | config.skip_session_storage = [:http_auth] 86 | 87 | # By default, Devise cleans up the CSRF token on authentication to 88 | # avoid CSRF token fixation attacks. This means that, when using AJAX 89 | # requests for sign in and sign up, you need to get a new CSRF token 90 | # from the server. You can disable this option at your own risk. 91 | # config.clean_up_csrf_token_on_authentication = true 92 | 93 | # When false, Devise will not attempt to reload routes on eager load. 94 | # This can reduce the time taken to boot the app but if your application 95 | # requires the Devise mappings to be loaded during boot time the application 96 | # won't boot properly. 97 | # config.reload_routes = true 98 | 99 | # ==> Configuration for :database_authenticatable 100 | # For bcrypt, this is the cost for hashing the password and defaults to 11. If 101 | # using other algorithms, it sets how many times you want the password to be hashed. 102 | # 103 | # Limiting the stretches to just one in testing will increase the performance of 104 | # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use 105 | # a value less than 10 in other environments. Note that, for bcrypt (the default 106 | # algorithm), the cost increases exponentially with the number of stretches (e.g. 107 | # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation). 108 | config.stretches = Rails.env.test? ? 1 : 11 109 | 110 | # Set up a pepper to generate the hashed password. 111 | # config.pepper = '8347a9864b498cc83cd1b364a9b99341c322901ac44bed0ee8e10fd3a2b82950ece175c26c823abf81fd91fefbf16364e4bd163195e115d8b3e408ce581057c6' 112 | 113 | # Send a notification email when the user's password is changed 114 | # config.send_password_change_notification = false 115 | 116 | # ==> Configuration for :confirmable 117 | # A period that the user is allowed to access the website even without 118 | # confirming their account. For instance, if set to 2.days, the user will be 119 | # able to access the website for two days without confirming their account, 120 | # access will be blocked just in the third day. Default is 0.days, meaning 121 | # the user cannot access the website without confirming their account. 122 | # config.allow_unconfirmed_access_for = 2.days 123 | 124 | # A period that the user is allowed to confirm their account before their 125 | # token becomes invalid. For example, if set to 3.days, the user can confirm 126 | # their account within 3 days after the mail was sent, but on the fourth day 127 | # their account can't be confirmed with the token any more. 128 | # Default is nil, meaning there is no restriction on how long a user can take 129 | # before confirming their account. 130 | # config.confirm_within = 3.days 131 | 132 | # If true, requires any email changes to be confirmed (exactly the same way as 133 | # initial account confirmation) to be applied. Requires additional unconfirmed_email 134 | # db field (see migrations). Until confirmed, new email is stored in 135 | # unconfirmed_email column, and copied to email column on successful confirmation. 136 | config.reconfirmable = true 137 | 138 | # Defines which key will be used when confirming an account 139 | # config.confirmation_keys = [:email] 140 | 141 | # ==> Configuration for :rememberable 142 | # The time the user will be remembered without asking for credentials again. 143 | # config.remember_for = 2.weeks 144 | 145 | # Invalidates all the remember me tokens when the user signs out. 146 | config.expire_all_remember_me_on_sign_out = true 147 | 148 | # If true, extends the user's remember period when remembered via cookie. 149 | # config.extend_remember_period = false 150 | 151 | # Options to be passed to the created cookie. For instance, you can set 152 | # secure: true in order to force SSL only cookies. 153 | # config.rememberable_options = {} 154 | 155 | # ==> Configuration for :validatable 156 | # Range for password length. 157 | config.password_length = 6..128 158 | 159 | # Email regex used to validate email formats. It simply asserts that 160 | # one (and only one) @ exists in the given string. This is mainly 161 | # to give user feedback and not to assert the e-mail validity. 162 | config.email_regexp = /\A[^@\s]+@[^@\s]+\z/ 163 | 164 | # ==> Configuration for :timeoutable 165 | # The time you want to timeout the user session without activity. After this 166 | # time the user will be asked for credentials again. Default is 30 minutes. 167 | # config.timeout_in = 30.minutes 168 | 169 | # ==> Configuration for :lockable 170 | # Defines which strategy will be used to lock an account. 171 | # :failed_attempts = Locks an account after a number of failed attempts to sign in. 172 | # :none = No lock strategy. You should handle locking by yourself. 173 | # config.lock_strategy = :failed_attempts 174 | 175 | # Defines which key will be used when locking and unlocking an account 176 | # config.unlock_keys = [:email] 177 | 178 | # Defines which strategy will be used to unlock an account. 179 | # :email = Sends an unlock link to the user email 180 | # :time = Re-enables login after a certain amount of time (see :unlock_in below) 181 | # :both = Enables both strategies 182 | # :none = No unlock strategy. You should handle unlocking by yourself. 183 | # config.unlock_strategy = :both 184 | 185 | # Number of authentication tries before locking an account if lock_strategy 186 | # is failed attempts. 187 | # config.maximum_attempts = 20 188 | 189 | # Time interval to unlock the account if :time is enabled as unlock_strategy. 190 | # config.unlock_in = 1.hour 191 | 192 | # Warn on the last attempt before the account is locked. 193 | # config.last_attempt_warning = true 194 | 195 | # ==> Configuration for :recoverable 196 | # 197 | # Defines which key will be used when recovering the password for an account 198 | # config.reset_password_keys = [:email] 199 | 200 | # Time interval you can reset your password with a reset password key. 201 | # Don't put a too small interval or your users won't have the time to 202 | # change their passwords. 203 | config.reset_password_within = 6.hours 204 | 205 | # When set to false, does not sign a user in automatically after their password is 206 | # reset. Defaults to true, so a user is signed in automatically after a reset. 207 | # config.sign_in_after_reset_password = true 208 | 209 | # ==> Configuration for :encryptable 210 | # Allow you to use another hashing or encryption algorithm besides bcrypt (default). 211 | # You can use :sha1, :sha512 or algorithms from others authentication tools as 212 | # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20 213 | # for default behavior) and :restful_authentication_sha1 (then you should set 214 | # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper). 215 | # 216 | # Require the `devise-encryptable` gem when using anything other than bcrypt 217 | # config.encryptor = :sha512 218 | 219 | # ==> Scopes configuration 220 | # Turn scoped views on. Before rendering "sessions/new", it will first check for 221 | # "users/sessions/new". It's turned off by default because it's slower if you 222 | # are using only default views. 223 | # config.scoped_views = false 224 | 225 | # Configure the default scope given to Warden. By default it's the first 226 | # devise role declared in your routes (usually :user). 227 | # config.default_scope = :user 228 | 229 | # Set this configuration to false if you want /users/sign_out to sign out 230 | # only the current scope. By default, Devise signs out all scopes. 231 | # config.sign_out_all_scopes = true 232 | 233 | # ==> Navigation configuration 234 | # Lists the formats that should be treated as navigational. Formats like 235 | # :html, should redirect to the sign in page when the user does not have 236 | # access, but formats like :xml or :json, should return 401. 237 | # 238 | # If you have any extra navigational formats, like :iphone or :mobile, you 239 | # should add them to the navigational formats lists. 240 | # 241 | # The "*/*" below is required to match Internet Explorer requests. 242 | # config.navigational_formats = ['*/*', :html] 243 | 244 | # The default HTTP method used to sign out a resource. Default is :delete. 245 | config.sign_out_via = :delete 246 | 247 | # ==> OmniAuth 248 | # Add a new OmniAuth provider. Check the wiki for more information on setting 249 | # up on your models and hooks. 250 | # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' 251 | 252 | # ==> Warden configuration 253 | # If you want to use other strategies, that are not supported by Devise, or 254 | # change the failure app, you can configure them inside the config.warden block. 255 | # 256 | # config.warden do |manager| 257 | # manager.intercept_401 = false 258 | # manager.default_strategies(scope: :user).unshift :some_external_strategy 259 | # end 260 | 261 | # ==> Mountable engine configurations 262 | # When using Devise inside an engine, let's call it `MyEngine`, and this engine 263 | # is mountable, there are some extra configurations to be taken into account. 264 | # The following options are available, assuming the engine is mounted as: 265 | # 266 | # mount MyEngine, at: '/my_engine' 267 | # 268 | # The router that invoked `devise_for`, in the example above, would be: 269 | # config.router_name = :my_engine 270 | # 271 | # When using OmniAuth, Devise cannot automatically set OmniAuth path, 272 | # so you need to do it manually. For the users scope, it would be: 273 | # config.omniauth_path_prefix = '/my_engine/users/auth' 274 | end 275 | -------------------------------------------------------------------------------- /config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure sensitive parameters which will be filtered from the log file. 4 | Rails.application.config.filter_parameters += [:password] 5 | -------------------------------------------------------------------------------- /config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, '\1en' 8 | # inflect.singular /^(ox)en/i, '\1' 9 | # inflect.irregular 'person', 'people' 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym 'RESTful' 16 | # end 17 | -------------------------------------------------------------------------------- /config/initializers/jbuilder.rb: -------------------------------------------------------------------------------- 1 | Jbuilder.key_format camelize: :lower 2 | -------------------------------------------------------------------------------- /config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | -------------------------------------------------------------------------------- /config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Rails.application.config.session_store :cookie_store, key: '_conduit_session' 4 | -------------------------------------------------------------------------------- /config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] if respond_to?(:wrap_parameters) 9 | end 10 | 11 | # To enable root element in JSON for ActiveRecord objects. 12 | # ActiveSupport.on_load(:active_record) do 13 | # self.include_root_in_json = true 14 | # end 15 | -------------------------------------------------------------------------------- /config/locales/devise.en.yml: -------------------------------------------------------------------------------- 1 | # Additional translations at https://github.com/plataformatec/devise/wiki/I18n 2 | 3 | en: 4 | devise: 5 | confirmations: 6 | confirmed: "Your email address has been successfully confirmed." 7 | send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes." 8 | send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes." 9 | failure: 10 | already_authenticated: "You are already signed in." 11 | inactive: "Your account is not activated yet." 12 | invalid: "Invalid %{authentication_keys} or password." 13 | locked: "Your account is locked." 14 | last_attempt: "You have one more attempt before your account is locked." 15 | not_found_in_database: "Invalid %{authentication_keys} or password." 16 | timeout: "Your session expired. Please sign in again to continue." 17 | unauthenticated: "You need to sign in or sign up before continuing." 18 | unconfirmed: "You have to confirm your email address before continuing." 19 | mailer: 20 | confirmation_instructions: 21 | subject: "Confirmation instructions" 22 | reset_password_instructions: 23 | subject: "Reset password instructions" 24 | unlock_instructions: 25 | subject: "Unlock instructions" 26 | password_change: 27 | subject: "Password Changed" 28 | omniauth_callbacks: 29 | failure: "Could not authenticate you from %{kind} because \"%{reason}\"." 30 | success: "Successfully authenticated from %{kind} account." 31 | passwords: 32 | no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided." 33 | send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes." 34 | send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes." 35 | updated: "Your password has been changed successfully. You are now signed in." 36 | updated_not_active: "Your password has been changed successfully." 37 | registrations: 38 | destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon." 39 | signed_up: "Welcome! You have signed up successfully." 40 | signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." 41 | signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked." 42 | signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account." 43 | update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirm link to confirm your new email address." 44 | updated: "Your account has been updated successfully." 45 | sessions: 46 | signed_in: "Signed in successfully." 47 | signed_out: "Signed out successfully." 48 | already_signed_out: "Signed out successfully." 49 | unlocks: 50 | send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes." 51 | send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes." 52 | unlocked: "Your account has been unlocked successfully. Please sign in to continue." 53 | errors: 54 | messages: 55 | already_confirmed: "was already confirmed, please try signing in" 56 | confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one" 57 | expired: "has expired, please request a new one" 58 | not_found: "not found" 59 | not_locked: "was not locked" 60 | not_saved: 61 | one: "1 error prohibited this %{resource} from being saved:" 62 | other: "%{count} errors prohibited this %{resource} from being saved:" 63 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # To learn more, please read the Rails Internationalization guide 20 | # available at http://guides.rubyonrails.org/i18n.html. 21 | 22 | en: 23 | hello: "Hello world" 24 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | scope :api, defaults: { format: :json } do 3 | devise_for :users, controllers: { sessions: :sessions }, 4 | path_names: { sign_in: :login } 5 | 6 | 7 | resource :user, only: [:show, :update] 8 | 9 | resources :profiles, param: :username, only: [:show] do 10 | resource :follow, only: [:create, :destroy] 11 | end 12 | 13 | resources :articles, param: :slug, except: [:edit, :new] do 14 | resource :favorite, only: [:create, :destroy] 15 | resources :comments, only: [:create, :index, :destroy] 16 | get :feed, on: :collection 17 | end 18 | 19 | resources :tags, only: [:index] 20 | end 21 | 22 | # The priority is based upon order of creation: first created -> highest priority. 23 | # See how all your routes lay out with "rake routes". 24 | 25 | # You can have the root of your site routed with "root" 26 | # root 'welcome#index' 27 | 28 | # Example of regular route: 29 | # get 'products/:id' => 'catalog#view' 30 | 31 | # Example of named route that can be invoked with purchase_url(id: product.id) 32 | # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase 33 | 34 | # Example resource route (maps HTTP verbs to controller actions automatically): 35 | # resources :products 36 | 37 | # Example resource route with options: 38 | # resources :products do 39 | # member do 40 | # get 'short' 41 | # post 'toggle' 42 | # end 43 | # 44 | # collection do 45 | # get 'sold' 46 | # end 47 | # end 48 | 49 | # Example resource route with sub-resources: 50 | # resources :products do 51 | # resources :comments, :sales 52 | # resource :seller 53 | # end 54 | 55 | # Example resource route with more complex sub-resources: 56 | # resources :products do 57 | # resources :comments 58 | # resources :sales do 59 | # get 'recent', on: :collection 60 | # end 61 | # end 62 | 63 | # Example resource route with concerns: 64 | # concern :toggleable do 65 | # post 'toggle' 66 | # end 67 | # resources :posts, concerns: :toggleable 68 | # resources :photos, concerns: :toggleable 69 | 70 | # Example resource route within a namespace: 71 | # namespace :admin do 72 | # # Directs /admin/products/* to Admin::ProductsController 73 | # # (app/controllers/admin/products_controller.rb) 74 | # resources :products 75 | # end 76 | end 77 | -------------------------------------------------------------------------------- /config/secrets.yml: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key is used for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | 6 | # Make sure the secret is at least 30 characters and all random, 7 | # no regular words or you'll be exposed to dictionary attacks. 8 | # You can use `rake secret` to generate a secure secret key. 9 | 10 | # Make sure the secrets in this file are kept private 11 | # if you're sharing your code publicly. 12 | 13 | development: 14 | secret_key_base: 1cedd34d1be5424c2646c82e267fcbb817dd118d47d52ea8835e7fd8ada93fcec1523148008c0ed647e5f852717692cb0236226929b02c97bfd032a275d5d87a 15 | 16 | test: 17 | secret_key_base: 7d4d2daa8c4b79efe9a9206d20b877a2cde9c90f46987c6ec24f811d06eddb9d554742fc6c25cd7ec73ce9e698424b152e78bb8bf61da8b669c53677f04ab0b8 18 | 19 | # Do not keep production secrets in the repository, 20 | # instead read values from the environment. 21 | production: 22 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> 23 | -------------------------------------------------------------------------------- /db/migrate/20160712045707_devise_create_users.rb: -------------------------------------------------------------------------------- 1 | class DeviseCreateUsers < ActiveRecord::Migration 2 | def change 3 | create_table :users do |t| 4 | ## Database authenticatable 5 | t.string :email, null: false, default: "" 6 | t.string :encrypted_password, null: false, default: "" 7 | 8 | ## Recoverable 9 | t.string :reset_password_token 10 | t.datetime :reset_password_sent_at 11 | 12 | ## Rememberable 13 | t.datetime :remember_created_at 14 | 15 | ## Trackable 16 | t.integer :sign_in_count, default: 0, null: false 17 | t.datetime :current_sign_in_at 18 | t.datetime :last_sign_in_at 19 | t.string :current_sign_in_ip 20 | t.string :last_sign_in_ip 21 | 22 | ## Confirmable 23 | # t.string :confirmation_token 24 | # t.datetime :confirmed_at 25 | # t.datetime :confirmation_sent_at 26 | # t.string :unconfirmed_email # Only if using reconfirmable 27 | 28 | ## Lockable 29 | # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts 30 | # t.string :unlock_token # Only if unlock strategy is :email or :both 31 | # t.datetime :locked_at 32 | 33 | 34 | t.timestamps null: false 35 | end 36 | 37 | add_index :users, :email, unique: true 38 | add_index :users, :reset_password_token, unique: true 39 | # add_index :users, :confirmation_token, unique: true 40 | # add_index :users, :unlock_token, unique: true 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /db/migrate/20160712045739_add_profile_fields_to_users.rb: -------------------------------------------------------------------------------- 1 | class AddProfileFieldsToUsers < ActiveRecord::Migration 2 | def change 3 | add_column :users, :username, :string 4 | add_index :users, :username, unique: true 5 | add_column :users, :image, :string 6 | add_column :users, :bio, :text 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /db/migrate/20160712052128_create_articles.rb: -------------------------------------------------------------------------------- 1 | class CreateArticles < ActiveRecord::Migration 2 | def change 3 | create_table :articles do |t| 4 | t.string :title 5 | t.string :slug 6 | t.text :body 7 | t.string :description 8 | t.integer :favorites_count 9 | t.references :user, index: true, foreign_key: true 10 | 11 | t.timestamps null: false 12 | end 13 | add_index :articles, :slug, unique: true 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /db/migrate/20160712054809_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb: -------------------------------------------------------------------------------- 1 | # This migration comes from acts_as_taggable_on_engine (originally 1) 2 | class ActsAsTaggableOnMigration < ActiveRecord::Migration 3 | def self.up 4 | create_table :tags do |t| 5 | t.string :name 6 | end 7 | 8 | create_table :taggings do |t| 9 | t.references :tag 10 | 11 | # You should make sure that the column created is 12 | # long enough to store the required class names. 13 | t.references :taggable, polymorphic: true 14 | t.references :tagger, polymorphic: true 15 | 16 | # Limit is created to prevent MySQL error on index 17 | # length for MyISAM table type: http://bit.ly/vgW2Ql 18 | t.string :context, limit: 128 19 | 20 | t.datetime :created_at 21 | end 22 | 23 | add_index :taggings, :tag_id 24 | add_index :taggings, [:taggable_id, :taggable_type, :context] 25 | end 26 | 27 | def self.down 28 | drop_table :taggings 29 | drop_table :tags 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /db/migrate/20160712054810_add_missing_unique_indices.acts_as_taggable_on_engine.rb: -------------------------------------------------------------------------------- 1 | # This migration comes from acts_as_taggable_on_engine (originally 2) 2 | class AddMissingUniqueIndices < ActiveRecord::Migration 3 | def self.up 4 | add_index :tags, :name, unique: true 5 | 6 | remove_index :taggings, :tag_id 7 | remove_index :taggings, [:taggable_id, :taggable_type, :context] 8 | add_index :taggings, 9 | [:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type], 10 | unique: true, name: 'taggings_idx' 11 | end 12 | 13 | def self.down 14 | remove_index :tags, :name 15 | 16 | remove_index :taggings, name: 'taggings_idx' 17 | add_index :taggings, :tag_id 18 | add_index :taggings, [:taggable_id, :taggable_type, :context] 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /db/migrate/20160712054811_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb: -------------------------------------------------------------------------------- 1 | # This migration comes from acts_as_taggable_on_engine (originally 3) 2 | class AddTaggingsCounterCacheToTags < ActiveRecord::Migration 3 | def self.up 4 | add_column :tags, :taggings_count, :integer, default: 0 5 | 6 | ActsAsTaggableOn::Tag.reset_column_information 7 | ActsAsTaggableOn::Tag.find_each do |tag| 8 | ActsAsTaggableOn::Tag.reset_counters(tag.id, :taggings) 9 | end 10 | end 11 | 12 | def self.down 13 | remove_column :tags, :taggings_count 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /db/migrate/20160712054812_add_missing_taggable_index.acts_as_taggable_on_engine.rb: -------------------------------------------------------------------------------- 1 | # This migration comes from acts_as_taggable_on_engine (originally 4) 2 | class AddMissingTaggableIndex < ActiveRecord::Migration 3 | def self.up 4 | add_index :taggings, [:taggable_id, :taggable_type, :context] 5 | end 6 | 7 | def self.down 8 | remove_index :taggings, [:taggable_id, :taggable_type, :context] 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /db/migrate/20160712054813_change_collation_for_tag_names.acts_as_taggable_on_engine.rb: -------------------------------------------------------------------------------- 1 | # This migration comes from acts_as_taggable_on_engine (originally 5) 2 | # This migration is added to circumvent issue #623 and have special characters 3 | # work properly 4 | class ChangeCollationForTagNames < ActiveRecord::Migration 5 | def up 6 | if ActsAsTaggableOn::Utils.using_mysql? 7 | execute("ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;") 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /db/migrate/20160712055201_create_favorites.rb: -------------------------------------------------------------------------------- 1 | class CreateFavorites < ActiveRecord::Migration 2 | def change 3 | create_table :favorites do |t| 4 | t.references :user, index: true, foreign_key: true 5 | t.references :article, index: true, foreign_key: true 6 | 7 | t.timestamps null: false 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /db/migrate/20160712061113_create_comments.rb: -------------------------------------------------------------------------------- 1 | class CreateComments < ActiveRecord::Migration 2 | def change 3 | create_table :comments do |t| 4 | t.text :body 5 | t.references :user, index: true, foreign_key: true 6 | t.references :article, index: true, foreign_key: true 7 | 8 | t.timestamps null: false 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /db/migrate/20160712061614_acts_as_follower_migration.rb: -------------------------------------------------------------------------------- 1 | class ActsAsFollowerMigration < ActiveRecord::Migration 2 | def self.up 3 | create_table :follows, force: true do |t| 4 | t.references :followable, polymorphic: true, null: false 5 | t.references :follower, polymorphic: true, null: false 6 | t.boolean :blocked, default: false, null: false 7 | t.timestamps 8 | end 9 | 10 | add_index :follows, ["follower_id", "follower_type"], name: "fk_follows" 11 | add_index :follows, ["followable_id", "followable_type"], name: "fk_followables" 12 | end 13 | 14 | def self.down 15 | drop_table :follows 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /db/schema.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | # This file is auto-generated from the current state of the database. Instead 3 | # of editing this file, please use the migrations feature of Active Record to 4 | # incrementally modify your database, and then regenerate this schema definition. 5 | # 6 | # Note that this schema.rb definition is the authoritative source for your 7 | # database schema. If you need to create the application database on another 8 | # system, you should be using db:schema:load, not running all the migrations 9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 10 | # you'll amass, the slower it'll run and the greater likelihood for issues). 11 | # 12 | # It's strongly recommended that you check this file into your version control system. 13 | 14 | ActiveRecord::Schema.define(version: 20160712061614) do 15 | 16 | create_table "articles", force: :cascade do |t| 17 | t.string "title" 18 | t.string "slug" 19 | t.text "body" 20 | t.string "description" 21 | t.integer "favorites_count" 22 | t.integer "user_id" 23 | t.datetime "created_at", null: false 24 | t.datetime "updated_at", null: false 25 | end 26 | 27 | add_index "articles", ["slug"], name: "index_articles_on_slug", unique: true 28 | add_index "articles", ["user_id"], name: "index_articles_on_user_id" 29 | 30 | create_table "comments", force: :cascade do |t| 31 | t.text "body" 32 | t.integer "user_id" 33 | t.integer "article_id" 34 | t.datetime "created_at", null: false 35 | t.datetime "updated_at", null: false 36 | end 37 | 38 | add_index "comments", ["article_id"], name: "index_comments_on_article_id" 39 | add_index "comments", ["user_id"], name: "index_comments_on_user_id" 40 | 41 | create_table "favorites", force: :cascade do |t| 42 | t.integer "user_id" 43 | t.integer "article_id" 44 | t.datetime "created_at", null: false 45 | t.datetime "updated_at", null: false 46 | end 47 | 48 | add_index "favorites", ["article_id"], name: "index_favorites_on_article_id" 49 | add_index "favorites", ["user_id"], name: "index_favorites_on_user_id" 50 | 51 | create_table "follows", force: :cascade do |t| 52 | t.integer "followable_id", null: false 53 | t.string "followable_type", null: false 54 | t.integer "follower_id", null: false 55 | t.string "follower_type", null: false 56 | t.boolean "blocked", default: false, null: false 57 | t.datetime "created_at" 58 | t.datetime "updated_at" 59 | end 60 | 61 | add_index "follows", ["followable_id", "followable_type"], name: "fk_followables" 62 | add_index "follows", ["follower_id", "follower_type"], name: "fk_follows" 63 | 64 | create_table "taggings", force: :cascade do |t| 65 | t.integer "tag_id" 66 | t.integer "taggable_id" 67 | t.string "taggable_type" 68 | t.integer "tagger_id" 69 | t.string "tagger_type" 70 | t.string "context", limit: 128 71 | t.datetime "created_at" 72 | end 73 | 74 | add_index "taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true 75 | add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context" 76 | 77 | create_table "tags", force: :cascade do |t| 78 | t.string "name" 79 | t.integer "taggings_count", default: 0 80 | end 81 | 82 | add_index "tags", ["name"], name: "index_tags_on_name", unique: true 83 | 84 | create_table "users", force: :cascade do |t| 85 | t.string "email", default: "", null: false 86 | t.string "encrypted_password", default: "", null: false 87 | t.string "reset_password_token" 88 | t.datetime "reset_password_sent_at" 89 | t.datetime "remember_created_at" 90 | t.integer "sign_in_count", default: 0, null: false 91 | t.datetime "current_sign_in_at" 92 | t.datetime "last_sign_in_at" 93 | t.string "current_sign_in_ip" 94 | t.string "last_sign_in_ip" 95 | t.datetime "created_at", null: false 96 | t.datetime "updated_at", null: false 97 | t.string "username" 98 | t.string "image" 99 | t.text "bio" 100 | end 101 | 102 | add_index "users", ["email"], name: "index_users_on_email", unique: true 103 | add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true 104 | add_index "users", ["username"], name: "index_users_on_username", unique: true 105 | 106 | end 107 | -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) 7 | # Mayor.create(name: 'Emanuel', city: cities.first) 8 | -------------------------------------------------------------------------------- /lib/assets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gothinkster/rails-realworld-example-app/a2ae4fff78b3337683cea988c023281dcb5551b9/lib/assets/.keep -------------------------------------------------------------------------------- /lib/tasks/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gothinkster/rails-realworld-example-app/a2ae4fff78b3337683cea988c023281dcb5551b9/lib/tasks/.keep -------------------------------------------------------------------------------- /log/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gothinkster/rails-realworld-example-app/a2ae4fff78b3337683cea988c023281dcb5551b9/log/.keep -------------------------------------------------------------------------------- /project-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gothinkster/rails-realworld-example-app/a2ae4fff78b3337683cea988c023281dcb5551b9/project-logo.png -------------------------------------------------------------------------------- /public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The page you were looking for doesn't exist.

62 |

You may have mistyped the address or the page may have moved.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The change you wanted was rejected.

62 |

Maybe you tried to change something you didn't have access to.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

We're sorry, but something went wrong.

62 |
63 |

If you are the application owner check the logs for more information.

64 |
65 | 66 | 67 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gothinkster/rails-realworld-example-app/a2ae4fff78b3337683cea988c023281dcb5551b9/public/favicon.ico -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | # 3 | # To ban all spiders from the entire site uncomment the next two lines: 4 | # User-agent: * 5 | # Disallow: / 6 | -------------------------------------------------------------------------------- /test/controllers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gothinkster/rails-realworld-example-app/a2ae4fff78b3337683cea988c023281dcb5551b9/test/controllers/.keep -------------------------------------------------------------------------------- /test/fixtures/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gothinkster/rails-realworld-example-app/a2ae4fff78b3337683cea988c023281dcb5551b9/test/fixtures/.keep -------------------------------------------------------------------------------- /test/fixtures/articles.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | title: MyString 5 | slug: MyString 6 | body: MyText 7 | description: MyString 8 | favorites_count: 1 9 | user_id: 10 | 11 | two: 12 | title: MyString 13 | slug: MyString 14 | body: MyText 15 | description: MyString 16 | favorites_count: 1 17 | user_id: 18 | -------------------------------------------------------------------------------- /test/fixtures/comments.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | body: MyText 5 | user_id: 6 | article_id: 7 | 8 | two: 9 | body: MyText 10 | user_id: 11 | article_id: 12 | -------------------------------------------------------------------------------- /test/fixtures/favorites.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | user_id: 5 | article_id: 6 | 7 | two: 8 | user_id: 9 | article_id: 10 | -------------------------------------------------------------------------------- /test/fixtures/users.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | # This model initially had no columns defined. If you add columns to the 4 | # model remove the '{}' from the fixture names and add the columns immediately 5 | # below each fixture, per the syntax in the comments below 6 | # 7 | one: {} 8 | # column: value 9 | # 10 | two: {} 11 | # column: value 12 | -------------------------------------------------------------------------------- /test/helpers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gothinkster/rails-realworld-example-app/a2ae4fff78b3337683cea988c023281dcb5551b9/test/helpers/.keep -------------------------------------------------------------------------------- /test/integration/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gothinkster/rails-realworld-example-app/a2ae4fff78b3337683cea988c023281dcb5551b9/test/integration/.keep -------------------------------------------------------------------------------- /test/mailers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gothinkster/rails-realworld-example-app/a2ae4fff78b3337683cea988c023281dcb5551b9/test/mailers/.keep -------------------------------------------------------------------------------- /test/models/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gothinkster/rails-realworld-example-app/a2ae4fff78b3337683cea988c023281dcb5551b9/test/models/.keep -------------------------------------------------------------------------------- /test/models/article_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class ArticleTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/comment_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class CommentTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/favorite_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class FavoriteTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/user_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class UserTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | ENV['RAILS_ENV'] ||= 'test' 2 | require File.expand_path('../../config/environment', __FILE__) 3 | require 'rails/test_help' 4 | 5 | class ActiveSupport::TestCase 6 | # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. 7 | fixtures :all 8 | 9 | # Add more helper methods to be used by all tests here... 10 | end 11 | -------------------------------------------------------------------------------- /vendor/assets/javascripts/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gothinkster/rails-realworld-example-app/a2ae4fff78b3337683cea988c023281dcb5551b9/vendor/assets/javascripts/.keep -------------------------------------------------------------------------------- /vendor/assets/stylesheets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gothinkster/rails-realworld-example-app/a2ae4fff78b3337683cea988c023281dcb5551b9/vendor/assets/stylesheets/.keep --------------------------------------------------------------------------------