• Stars
    star
    122
  • Rank 291,356 (Top 6 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A demo app to show some Rails app configurations

Cybros Core

CircleCI

This is a barebone Rails 6.0 app to show some basic configurations.

I'm used to maintaining a barebone app that helps me build new project quickly, and this is extracted from my side project initially for sharing my ideas to friends, but if this is valuable to you, use it freely.

Goal

I hope this could be a template for new apps, it should be production-ready, so I'll keep polishing the codebase, follow best practice, keep dependencies up to date.

I don't wanna add too much features especially business-specific, but I'd like to perfection User system (based on Devise) because most apps need this, and keep improving UI/UX relates works.

BTW: I'm really hoping someone could extract GitLab's user system.

I list some helps wanted, see below.

Features

Classic front-end

Personally, I'm not skilled at front-end and I still prefer classic Rails server-side rendering, and partially introduce React or Vue for complex pages.

A good example is Gitlab, I also cheat some useful helpers to this app.

Webpacker 5 without Sprockets

Webpacker can do all the jobs that Sprockets does, and has full support of front-end community, So I remove Sprockets and tune Webpacker allows Assets Pipeline experience.

I do these:

  • Remove gems related to Sprockets
  • Search and remove assets related configs
  • resolved_paths: ['app/assets'] in config/webpacker.yml
  • app/javascript/packs/application.js require all static assets (images, webfonts, etc.)

CoreUI with Bootstrap, FontAwesome

See app/assets/stylesheets/application.scss

Application configuration

A hack about Rails Credentials

Rails Credentials is a useful feature to store security-sensitive configs.

But we can't bundle master.key, and credentials.yml.enc isn't readable, so it's difficult to redistribute the app, I gave a PR to Rails but no respond, I consistantly think it's useful so I integrate it as a hack, see bin/rails.

So you can copy config/credentials.yml.example as config/credentials.yml, edit it, then run rails credentials:encrypt that will generate config/credentials.yml.enc and config/master.key for you.

A hack about ActionMailer configuration

Unlike database.yml, ActionMailer's config separates in many files, I do a hack that you can config ActionMailer in one place.

See config/mailer.yml

Codes in config/application.rb

Implemented a full-feature layouts & views

I don't have art skill but ... at least it works!

Overrides Form Helpers to enhance them to support Bootstrap form validation style

The technique is in https://guides.rubyonrails.org/engines.html#implementing-decorator-pattern-using-class-class-eval

See app/overrides/action_view/helpers/form_builder_override.rb

In addition, see config/application.rb for how to require overrides.

Don't render ActionView's default error field wrapper

That will break many CSS frameworks.

See config/initializers/action_view.rb

Default value for model fields

See app/models/concerns/acts_as_default_value.rb

Default value of column can only be a static value, Active Record's attribute DSL can set default for field but doesn't have entity context, Using hooks (such as after_initilize) to set default values has edge cases, you can use default_value_for to set default value.

Here's a complex example:

default_value_for :role_id,
                    -> (member) {
                      if member.has_attribute?(:tenant_id) || member.tenant
                        member&.tenant&.member_role&.id
                      end
                    }, allow_nil: false

I18n for enum

See app/models/concerns/enum_attribute_localizable.rb

Rails doesn't have best practice for enum I18n, I integrate my personal practice.

For example, I have a model Post with status column for enum

class Post < ApplicationRecord
  enum status: %i[draft published archived]
end

The locale post.en.yml looks like

en:
  activerecord:
    models:
      post: Post
    attributes:
      post:
        status: Status
        statuses:
          draft: Draft
          published: Published
          archived: Archived

To render human readable post's status, you can do like this:

Post.human_enum_value(:status, @post)

Undocumented yet

TODO:

Run the app

  • Clone it
  • bundle
  • yarn
  • cp config/database.yml.example config/database.yml
  • cp config/credentials.yml.example config/credentials.yml & rails credentials:encrypt
  • cp config/mailer.yml.example config/mailer.yml
  • rails db:migrate
  • rails s

Receive Devise confirmation mail

In development, I use mailcatcher to receive mails, run gem install mailcatcher to install it.

Open a new terminal, run mailcatcher, then follow the instructions

Set user as admin

  • cp config/settings.yml config/settings.local.yml
  • Put your email into admin.emails
  • In user menu (right-top of pages), you should see Administration

Troubleshooting

Make sure run gem update --system to use latest Rubygem

Help wanted

  • UI/UX design & SCSS & HTML improvement
  • Layout for mails
  • Coding style & structural improvement
  • Try support uploading user avatar using ActiveStorage
  • Find bugs
  • Docker for deployment, including stages to compiling assets & copy ymls, easy to migrate to k8s

Screenshots

Sign in page Admin user page

License

MIT License.

More Repositories

1

wx_pay

An unofficial simple wechat pay gem
Ruby
460
star
2

a_rails_start_up_omakase

A pre-configured Rails app for startup, focusing on oauth, deployment and maintenance
Ruby
97
star
3

RouterX

A Ruby on Rails flavoured URL routing engine in Swift.
Swift
88
star
4

MoyaX

Network abstraction layer written in Swift, based on Moya
Swift
77
star
5

activeentity

Active Record without Database
Ruby
52
star
6

ueditor_rails

[Abandoned] UEditor integration with Rails
HTML
27
star
7

jasl_tenpay

An unofficial simple tenpay gem
Ruby
18
star
8

RubyChinaAPP

Ruby China iOS app of jasl's edition
Swift
17
star
9

haven

a blog like octopress, based on middleman
Ruby
12
star
10

tenpay_demo

test tenpay
Ruby
11
star
11

tick-tock

a web app to provide dairy service. using rails and mongoid. It's just for learning. : )
Ruby
10
star
12

chatroom.js

a simple chatroom based on node.js and websocket, just for fun~
JavaScript
5
star
13

a-front-end-form-validator

a simple front-end form validator. easy for expanding.
JavaScript
3
star
14

harvest2

Ruby
2
star
15

jasl.github.io

jasl's personal blog
Groovy
2
star
16

small_yellow_ji

ไบบไบบ็ฝ‘ๅฐ้ป„้ธกๅฑฑๅฏจ็‰ˆ https://github.com/wong2/xiaohuangji
Ruby
1
star
17

playgrounds

personal playgrounds
Swift
1
star
18

log_watcher

a simply gem to watch rails logs, very very crude
Ruby
1
star
19

shopify_stdlib_mutable

Ruby
1
star
20

dentaku_calculator

A playground for Dentaku (an expression evaluator)
Ruby
1
star
21

middleman-blog_page

Blog page engine for Middleman
Ruby
1
star
22

zk_dcap_verifier_poc

Rust
1
star
23

monte_carlo_chainlink_functions

Solidity
1
star
24

Not-A-Framework-on-PHP

This is a very lightweight and biz-oriented framework and not using MVC pattern, it integrated smarty for presentation, redbean for ORM. I call a page app or dispatch app, and you just need inherit it and rewrite do_post and do_get or forward method, then call its run method and see.
PHP
1
star