Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Stripe subscription model integrated with Ruby on Rails.

Notifications You must be signed in to change notification settings

liveinsights/clone-monthly-subscriptions

Repository files navigation

Pre-setup

Installing Ruby on Rails on OS X.


Getting Started

Install Libraries

brew install mysql
brew install mysql@56
bundle install

Create a New App

Create new rails app with mysql as the default.

rails new <my_rails_app> --database=mysql

Starting your Web Server using rerun

Default rails comes with Webrick but I dislike having to stop and restart my web server regularly. Instead, I use rerun to monitor my file edits and restart the server every time I make a change. livereload is also very popular.

rerun --dir config rails s

Viewing your work

If you leave all the settings on default, you should be able to access your new website on:

http://localhost:3000

Rails-specific commands

I generally recommend that new rails developers get into the habit of manually creating their own controllers, routes, view templates and partials but scaffolding can come in handy too.

Models

Models are the classes that you use to populate and retrieve data from a database. They're exceptionally useful for validating data before you write anything to a database so treat them with kindness and respect.

Creating a Model

rails g model mymodel title:string description:text file_url:string

Controllers

Controllers are the methods you use to access data, manipulate it, and publish it to view templates. These methods are oftentimes accessed by admin/routes which are triggered by REST requests.

rails g scaffold_controller ClassName

is the shorthand way of writing this:

rails g controller mycontroller new create update edit destroy index show

Fixing a Mistake

If you mess up your command and you need to re-build your controller, I suggest trying this. It will re-create (and forcefully overwrite) your controller and views and skip the migration.

rails generate mycontroller new create update edit destroy index show --migration=false --skip -f

Edit Rails scaffold class to add a new field

We're going to add a string column to MyModel

rails generate migration add_[my_column]_to_[mymodel] my_column:string
rake db:migrate

Other Gems

  • Devise is great for creating a user authentication system. If you need signup, log in, log out and sign out, Devise is perfect for your eneds.

  • Jade Templates are easier to work with than erb and slim. This is a personal preference but I also prefer Jade because it works with Node and ExpressJS.

  • Administration: If you need a complicated user system with permissions and governance. Cancan, pundit, rolify are very popular.

  • Installing a gem

bundle install