Coder Social home page Coder Social logo

brunofacca / zen-rails-base-app Goto Github PK

View Code? Open in Web Editor NEW
665.0 31.0 96.0 162 KB

Base application for Ruby on Rails 6 projects. Built to minimize the time spent writing boilerplate code and performing repetitive setup tasks.

License: MIT License

Ruby 72.02% JavaScript 4.53% HTML 17.38% SCSS 6.07%

zen-rails-base-app's Introduction

Zen Rails Base Application

Summary

Base or "skeleton" application for Ruby on Rails 6.1 projects. Built to minimize the time spent writing boilerplate code and performing repetitive setup tasks.

It comes with a preselected set of tools which I believe to be the most effective and widely used. If you are looking for greater flexibility, an application template which uses Rails's templating system such as Rails Composer should be a better fit as it allows the user to choose which templating engine, test framework, JS framework and other tools to use.

Although this project is opinionated regarding tool choices, community feedback and contributions are always welcome and highly appreciated.

Features

It consists of a Rails 6.1.4 app, including:

  • A selection of useful gems for development and debugging such as rubocop, brakeman, awesome_print, byebug, and better_errors.

  • Preconfigured test environment, including:

  • Preconfigured authentication with the Devise gem.

  • Preconfigured authorization with the Pundit gem.

  • Internationalization (i18n)

    • All of the base application's strings are in YML dictionaries. This is arguably a good practice even for single language applications. Having an internationalized base application makes it easier and faster to translate elements like Devise, the layout and error messages when creating a single language app in a non-English language.
    • Methods for translating enum attributes, including the generation of translated options for select boxes. Implemented and documented in app/models/application_record.rb
  • jQuery

  • HTML Layouts developed with Bootstrap 3 (bootstrap-sass gem) to use as a starting point, including:

    • Navigation bar;
    • Displaying of flash messages and validation errors as Bootstrap alerts;
    • Role-based layout switching: different layouts for guests (unauthenticated users), ordinary users and admins;
  • Controller concerns such as SkipAuthorization.

  • User-friendly error messages (flash) on exceptions such as ActiveRecord::DeleteRestrictionError and Pundit::NotAuthorizedErrorand.

  • User management interface for admins in /admin/users with pagination (kaminari gem) and searching/filtering (ransack gem). Accessible only by users with "admin" role.

  • Seed users for the development environment.

  • Contact form built with the mail_form gem.

  • E-mails "sent" in the development environment are saved as html files in tmp/letter_opener (letter_opener gem).

  • The following JavaScript libraries:

    • Select2 for better select boxes.
    • SweetAlert2 for better JS popups, including the replacement of the default data-confirm confirmation by a better-looking version.
    • ZenUtils: a small JavaScript library consisting of utility functions. See app/assets/javascripts/zen-utils.js.
  • SCSS utility classes for alignment, spacing and font size standardization. See app/assets/stylesheets/utility-classes.scss.

  • High test coverage.

Development Environment Dependencies

  • Ruby 3.0.2
  • Yarn (requires Node.js)
  • Required for running JavaScript-enabled feature specs:

Usage

Setup tasks such as configuring time zones, default locale and action mailer (e.g., SMTP or transactional e-mail service) are not included in the following steps as they are not specific to this base app.

  1. Fork this repository.

  2. Clone the forked repository to your machine.

  3. Rename the application:

    1. Required: change the module name in config/application.rb from ZenRailsBaseApp to your application name, in camel case.
    2. Optional: Use your IDE's "search all files" feature to find and replace the following strings:
      • Replace zen_rails_base_app by your_app_name
      • Replace ZEN_RAILS_BASE_APP by YOUR_APP_NAME
      • Replace Project Name by the project's name
      • Replace [email protected] manually by the different e-mail addresses that should send and receive e-mails in various parts of the application.
  4. Run bundle install to install the gems listed in the Gemfile and their dependencies.

  5. Run yarn install to install the front end (JavaScript) packages listed in packages.json and their dependencies.

  6. Configure the databases:

    1. If using PostgreSQL, uncomment the pg gem from the Gemfile. If using MySQL, uncomment the mysql2 gem.

    2. Uncomment the section of config/database.yml corresponding to your chosen DBMS.

    3. If you don't have a DB user (with a password) yet, create one.

    4. Edit the following fields ofconfig/database.yml:

      • database.development
      • database.test
      • default.username
      • default.password
  7. Before attempting to run the application or its test suite, run rails db:create db:migrate db:seed within the project's root directory. That will create the following seed users:

  8. Customise the authentication setup. You may want to change one or more of the following items:

    • Aside from Devise's default attributes, the User model also has role, first_name, and last_name attributes.
    • Aside from the Devise's default modules, this app also uses Confirmable, Timeoutable and Lockable.
    • Pundit is used for for authorization. The User model has an enum attribute called role. Its possible values are :user and :admin. The default value is :user.
  9. Customize the application colors by overwriting Bootstrap's variables in app/assets/stylesheets/global.scss.

  10. Remove unused items from the application, such as gems from the Gemfile, RSpec helpers, custom matchers and shared examples from spec/support.

  11. Consider going through the Zen Rails Security Checklist before deploying the application to production.

TODO (PRs welcome)

  • Dockerize. Set up all development dependencies in the Dockerfile.
  • Set up continuous integration.
  • Fix remaining Rubocop offenses
  • Upgrade Bootstrap 3 to Bootstrap 5
  • Install and configure the Secure Headers gem.
  • Set up CodeClimate with Rubocop, Reek, Brakeman, and ESLint engines.
  • Use Yarn instead of gems to install front end libraries such as jQuery and Select2.
  • Add an asterisk to the labels of required form fields.
  • Internationalize and translate the JS front end, mainly global.js and zen-utils.js.

Authors

  • Bruno Facca - Email: bruno at facca dot info - LinkedIn

Contributing

Bug reports

Please use the issue tracker to report any bugs.

Developing

  1. Create an issue and describe your idea
  2. Fork it
  3. Create your feature branch (git checkout -b my-new-feature)
  4. Commit your changes (git commit -m 'Add some feature')
  5. Publish the branch (git push origin my-new-feature)
  6. Create a Pull Request

License

Released under the MIT License.

zen-rails-base-app's People

Contributors

brunofacca avatar malachaifrazier avatar nstoker avatar stmcintyre avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zen-rails-base-app's Issues

Error on initial page load

After following the instructions in the readme, I'm getting this error when I try to navigate to the page:

Started GET "/users/sign_in" for 172.16.1.106 at 2017-08-31 18:12:32 -0400
2017-08-31 18:12:32 -0400: Rack app error handling request { GET /users/sign_in }
#<NoMethodError: undefined method `*' for nil:NilClass>
Error reached top of thread-pool: undefined method `join' for nil:NilClass (NoMethodError)

I can't seem to figure out where it's coming from. Any ideas?

Potential information leakage in show_user_not_authorized_error

Problem

The show_user_not_authorized_error handler could potentially leak sensitive information depending on the application. For example, lets say you have a project management application with urls like: /:organization/:project_name. I could visit /google/slack-acquisition and check the response code. If I get a 404, then the project doesn't exist, but if I get a 2XX/3XX, then I can assume that Google may be about to acquire Slack.

Suggested solution

When pundit raises not authorized, simply render the standard 404 page.

missing sweetalert2 gem in Gemfile?

I did a localhost install in 8/29. localhost:3000/users/sign_in fails with the following msg:

couldn't find file 'sweetalert2/dist/sweetalert2' with type 'text/css'

/assets/stylesheets/aplication.scss includes the following :

*= require sweetalert2/dist/sweetalert2

I didn't see this gem in Gemfile. Did I miss something?

How to list all the users

Hey sorry, it's not actually an issue. I don't know how to reach you in person.I am using your base app Its really amazing thank you
I have to do the list all the users from the database and show their details, could you guide me the best possible way to do this as of now admin has all the power to CRUD the user but I need to have the show and index action for the nonadmin user. And have to use all the powers of pundit.
I know it's not related to your repository but It could really help me. Thanks in advance

Use `sweetalert2` gem

A shameless self-plug here, but I did finally update the sweetalert2 gem to the latest version from the CDN (7.25.6)

Feel free to use it, in order to be consistent with the other JS libraries that you are including.

https://github.com/KMontag42/sweetalert2-rails

Please close this if it is not appropriate ๐Ÿ˜„

โค๏ธ

Seed file contains duplicate email addresses

Seed file has '[email protected]' for both the Admin and Ordinary user. This results the following error whilst trying to seed:

ActiveRecord::RecordInvalid: Validation failed: E-mail has already been taken

I believe the correct email for the ordinary user should be '[email protected]' as per the Readme.

Thanks for taking the time to set this base app up and sharing. I'll create a small PR to fix the typo.

Rails --api mode when ?

I was just wondering if you guys are thinking of handeling rails api mode and what are the plans for that ?
Thanks

Error deploying to production

Hi,

I played with your app in development, and all is working good (good job !).
But I got an error when trying to deploy to production.
When "bundle exec rake assets:precompile" is executed :

"rake aborted!
ExecJS::RuntimeError: SyntaxError: Unexpected token: name (Library)
JS_Parse_Error.get ((execjs):3538:621)"

Do you already got this issue ?
Am I missing something ?

Thanks


See the full error message below :

rake aborted!
ExecJS::RuntimeError: SyntaxError: Unexpected token: name (Library)
JS_Parse_Error.get ((execjs):3538:621)
(execjs):4060:48
(execjs):1:102
Object. ((execjs):1:120)
Module._compile (module.js:643:30)
Object.Module._extensions..js (module.js:654:10)
Module.load (module.js:556:32)
tryModuleLoad (module.js:499:12)
Function.Module._load (module.js:491:3)
Function.Module.runMain (module.js:684:10)
/home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/execjs-2.7.0/lib/execjs/external_runtime.rb:39:in exec' /home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/execjs-2.7.0/lib/execjs/external_runtime.rb:21:in eval'
/home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/execjs-2.7.0/lib/execjs/external_runtime.rb:46:in call' /home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/uglifier-3.2.0/lib/uglifier.rb:195:in run_uglifyjs'
/home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/uglifier-3.2.0/lib/uglifier.rb:157:in compile' /home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/uglifier_compressor.rb:53:in call'
/home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/uglifier_compressor.rb:28:in call' /home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:75:in call_processor'
/home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:57:in block in call_processors' /home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in reverse_each'
/home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in call_processors' /home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/loader.rb:134:in load_from_unloaded'
/home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/loader.rb:60:in block in load' /home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/loader.rb:317:in fetch_asset_from_dependency_cache'
/home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/loader.rb:44:in load' /home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:20:in block in initialize'
/home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:47:in load' /home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/base.rb:66:in find_asset'
/home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/base.rb:73:in find_all_linked_assets' /home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:142:in block in find'
/home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:114:in block (2 levels) in logical_paths' /home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:228:in block in stat_tree'
/home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:212:in block in stat_directory' /home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in each'
/home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in stat_directory' /home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:227:in stat_tree'
/home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:105:in each' /home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:105:in block in logical_paths'
/home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:104:in each' /home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:104:in logical_paths'
/home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:140:in find' /home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:185:in compile'
/home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:68:in block (3 levels) in define' /home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/rake/sprocketstask.rb:147:in with_logger'
/home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:67:in block (2 levels) in define' /home/deploy/test-env-dev/shared/bundle/ruby/2.4.0/gems/rake-12.3.0/exe/rake:27:in '
/home/deploy/.rbenv/versions/2.4.2/bin/bundle:23:in load' /home/deploy/.rbenv/versions/2.4.2/bin/bundle:23:in
'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.