SkillCrafting: Building an Online Learning Platform with Ruby on Rails
The following is a collection of links that were useful to me when writing SkillCraft, my third portfolio project in the Flatiron School software engineering program.
After a solid background with Sinatra in the previous project, I felt I could get the gist of Rails more effectively by learning by doing and focusing on my project. The labs are valuable, but I am less interested in drilling myself with fundamentals than going deeper into Active Record, which was one of the goals of this project for me.
So, about half way through the Rails labs, I decided to jump directly to the project. I wanted to somewhat simulate how it will likely be when I join a new development team, having to learn something complete new on the fly, while making something at the same time.
The jury is still out on this strategy. I am about a month and a half late on aggressive deadline I gave myself and I still have 20+ labs to complete before review next Monday 😟. It will hopefully be easier now to go through the labs because I have some experience with these concepts.
The following is a collection of links that I found useful to progress through the requirements of the project. I hope you find something useful!
Conjure Up Some ERDs
Generate Entity-Relationship Diagrams for Rails applications. This is a gem that I am glad I took the time to explore. It auto generates an ERD diagram for you by looking at your tables and relationships. I am pretty happy with the result. Here’s a progression of ERD diagrams generated as I built the web app.
Grow Some Seeds
The rake db:seed command will populate your database from /db/seeds.rb.
This link explains how to generate your own seeds.rb file from the current state of your database. As I was building the app, I added data through the web interface interface I was building. Re-seeding allowed me to save entered data and easily re-populate if I needed to start over and/or experiment with models.
sample seeds.rb:User.create({“id”=>1, “provider”=>nil, “uid”=>nil, “user_name”=>”LarryTeacher”, “avatar_id”=>1, “type”=>”Teacher”, “password_digest”=>”#”, “first_name”=>”Larry”, “last_name”=>”Teacher”, “email”=>”larry@email.com”, “created_at”=>”Thu, 11 Jun 2020 22:25:27 UTC +00:00", “updated_at”=>”Thu, 11 Jun 2020 22:25:27 UTC +00:00" })User.create({“id”=>2, “provider”=>nil, “uid”=>nil, “user_name”=>”MoeTeacher”, “avatar_id”=>2, “type”=>”Teacher”, “password_digest”=>”#”, “first_name”=>”Moe”, “last_name”=>”Teacher”, “email”=>”moe@email.com”, “created_at”=>”Thu, 11 Jun 2020 22:25:27 UTC +00:00", “updated_at”=>”Thu, 11 Jun 2020 22:25:27 UTC +00:00" })Course.create({“id”=>1, “name”=>”Writing”, “code”=>”1111", “image_url”=>”https://res.cloudinary.com/fergusdev/image/upload/v1591290485/subjects/writing_100x100_rbvmxk.png", “featured”=>true, “tuition_cost”=>0, “short_desc”=>”Short story writing.”, “long_desc”=>”Long description.”, “created_at”=>”Thu, 11 Jun 2020 18:57:35 UTC +00:00", “updated_at”=>”Tue, 09 Jun 2020 22:17:18 UTC +00:00" })Course.create({“id”=>2, “name”=>”Math”, “code”=>”2222", “image_url”=>”https://res.cloudinary.com/fergusdev/image/upload/v1591290485/subjects/math_100x100_no9cxv.png", “featured”=>false, “tuition_cost”=>20, “short_desc”=>”Build fundamentals.”, “long_desc”=>”Bla bla bla”, “created_at”=>”Thu, 11 Jun 2020 18:57:35 UTC +00:00", “updated_at”=>”Thu, 11 Jun 2020 18:57:35 UTC +00:00" })...
This is a gem that automatically creates the seeds.rb file. I couldn’t get this to work though. I think it doesn’t work on Rails 6, not sure.
Where Are We Goin?
The /config/routes.rb file is important to define the routes or valid paths of the application. I referred to this link multiple times throughout the application.
Active Record Validations Rock
One of the great powers of AR is that it has a robust set of built-in validation methods that abstract away the need to write them by hand.
Some validations explored/implemented in the web app were the following…
How do I validate to allow blanks but not nil/null?
How do I validate that a field is an integer?
How do I validate that the field value is contained within a set array of values?
How do I validate that the field is a valid email address?
Custom Validations
Additionally, if you have a particularly weird validation that you need to enforce, you can add a custom validation. Active Record provides elegant methods to keep your database clean.
General guide to custom validations
How to use custom validation error messages
More on how to use custom validations
Even more on how to use custom validations
More examples
More information about custom validations
Omni-Auth with twitter
One of the requirements of the project was to implement an “authentication system that allows for login from some other service. Facebook, Twitter, Foursquare, Github, etc.”
The following links helped to implement the sign in with twitter functionality on the site.
Coding Bootcamp Lecture: Using Omniauth in Rails 5
OmniAuth is a flexible authentication system utilizing Rack middleware
Rails 5.0 starter app with OmniAuth for authentication
Help setting up twitter api key
Twitter Sign In with Rails and OmniAuth
How to Use OmniAuth-Twitter in a Rails Application
Twitter Authentication Guide: Log in with Twitter
Issues with has_secure_password and OmniAuth
How to pass parameters through OmniAuth authorization
(used this when user is signing in as a Teacher or a Student)
Leverage the Power of the Dark Side (VSCode)
Want to get the most out of VSCode? Check these links out:
Beginners guide for a Ruby-on-Rails ready Visual Studio Code
The three extensions you need for Rails development in VS Code
Enable Formatting with ERB files in VScode
The RuboCop extension has made me a better coder, indeed.
Form Helper Encounters
They are cool, but found myself struggling a bit to remember syntax. I understand the purpose/value of these helpers, but noting that they are Rails specific.
Rails 5.1’s form_with vs. form_tag vs. form_for
Collection_select: What the heck?
Rails docs about link_to
Rails docs about collection_radio_buttons
Action View Form Helpers
Rails docs about button_to
Model Relationships and Inheritance
One of the challenges that I set up for myself in this project was to use inheritance to keep the code DRY. I found myself waffling in places with regards to this.
In this project, Student and Teacher models inherit from User. Announcements and Assignments inherit from Interaction. Questions and CompletedAssignments inherit from Response. These links helped me work through the relationship magic of AR.
How a has_many :through association works in practice
Use through option on a belongs_to ActiveRecord association
Rails has_one :through association
Combining has_many :through with polymorphic associations in ActiveRecord
Multiple has_many relationships to same model
Let’s Make An Animated GIF
EZ gif is amazing. If you ever need to create an animated gif, edit one or anything else, this site has you covered. I used it to produce this evolution of my database erd animation above.
Keep Your Keys in Your Pocket
Dotenv is a good gem for keeping api keys (and other things) secret. Don’t for get to add *.env to your .gitignore.
How to Set Environment Variables in Linux
Image Management
Cloudinary can create, manage, and deliver images, videos and other media, personalized and optimized for every device and channel.
This utility is very useful. It enables images in your site when hosted on Heroku.
Check Out these Repos
I found them interesting for one reason or another. I likely borrowed from them in some manner.
https://github.com/mattgstevens/angelhack2013-drip
https://alankrajina.github.io/pizzaonrailsapp_-_rails_project
https://github.com/eclectic-coding/rails-movie-browser
Old Tool Still Shines
Beyond Compare is probably the oldest tool I have in my programming toolbox. It is excellent for comparing different versions of code. Has many cool features. Very much worth paying for.
The Wizard
Here is the source of the Wizard graphic.
Subject Icons
Here is the source of the Subject Icons
Funny Lorem Ipsums
Star Wars Ipsum
star trek ipsum
A Happy Lorem Ipsum: Bob Ross quotes generator
Great Image Utility
Use ImageMagick® to create, edit, compose, or convert bitmap images. It has a gem too. Thanks Big Mike for pointing here.
Miscellaneous
Rails doc on becomes. I probably need to refactor this out.
Need custom text for a form_for label?
Rails: set params but do not save