Skip to content

Repository files navigation

README

Learning App for Moms Learn to Code, find it at https://learn.momslearntocode.com.

Rails Style Guide

Install

Clone the repository

git clone git@github.com:hhar/mltc_learning_app.git
cd mltc_learning_app

Check your Ruby version

ruby -v

The ouput should start with something like ruby 3.0.2

If not, install the right ruby version using rbenv (it could take a while):

rbenv install 3.0.2

Install dependencies

Using Bundler and Yarn:

bundle && yarn

Initialize the database

rails db:create db:migrate db:seed

Serve

rails s

Deploy

With fly

fly deploy

Rails Console

Locally

rails console

On Fly.io (production)

fly ssh console --pty -C "/app/bin/rails console"

The --pty flag is required to allocate a pseudo-TTY, otherwise IRB raises an Errno::ENOTTY error.

Lesson Materials

Editing via the UI (recommended)

You must be logged in as an admin. Navigate to:

/lessons/<lesson_id>/materials/<material_id>/edit

To list all materials for a lesson:

/lessons/<lesson_id>/materials

Editing via the Rails console

Find a material:

# By lesson name
lesson = Lesson.find_by(name: "HTML and CSS Introduction")
lesson.materials

# Find a specific task material
task = lesson.materials.where(type: "TaskMaterial").first
# or by id
task = TaskMaterial.find(87)

View content:

task.body.to_plain_text
task.body.body.to_html

Update content:

task.body = "<ol><li>New task text</li></ol>"
task.save!

Find and replace within existing content:

new_html = task.body.body.to_html.gsub("old string", "new string")
task.body = new_html
task.save!

Always assign to task.body = directly (not task.body.body =), otherwise Rails won't detect the change and won't save it.

Creating a material via the console

lesson = Lesson.find_by(name: "My Lesson")
TaskMaterial.create!(lesson: lesson, body: "<ol><li>Task 1</li></ol>")

Adding a course to a user

user = User.find_by(email: "user@example.com")
user.courses << Course.find_by(title: "Course Title")
# or explicitly:
Subscription.create!(user: user, course: Course.find(1))

Releases

Packages

Used by

Contributors

Languages