15 Simple Steps to Creating a CRUD Web App with Ruby on Rails

15 Simple Steps to Creating a CRUD Web App with Ruby on RailsDanielle JasperBlockedUnblockFollowFollowingMay 1If you are fairly new to Ruby on Rails (or forgot how to use it) and need a quick guide to creating a CRUD (create, read, update, destroy) web application, then you’ve come to the right place!Below I have written some simple steps to creating a very simple application, linked to some documentation or a tutorial for each step, and included an example of what you might write for each step.

Here’s a nice, simple tutorial that gives some more context and explanation and walks you through these steps.

This guide is also fairly easy to follow, much longer, and more detailed.

Create a new apprails new pets-app2.

Launch a server and go to http://localhost:3000 in your browser to view your apprails s3.

Create modelsrails g model owner first_name last_name age:integer emailrails g model pet name species owner_id:integer owner:belongs_to4.

Set up associationsclass Owner < ApplicationRecord has_many :petsend5.

Add validationsclass Owner < ApplicationRecord has_many :pets validates :name, presence: trueend6.

Run migrationsrails db:migrate7.

Check your schema by looking at the db/schema.

rb file8.

Seed your databaseOwner.

create!(first_name:"Dan", last_name:"Weirdo", age: 18, email:"realemail@cool.

com")Pet.

create!(name:"Snowball", species:"dog", owner_id:1)9.

Test associationsOwner.

first.

petsPet.

first.

owner10.

Test validationsowner = Owner.

new(first_name: "")owner.

valid?owner.

errors.

messages11.

Create controllers and viewsrails g controller owners index show new create edit update destroyrails g controller pets index show new create edit update destroy12.

Create routes using resources or manual routesresources :petsresources :owners13.

Make sure your routes are working correctly by running your server(rails s) and looking at each path that you created (i.

e.

/pets)14.

Add/edit controller actionsHint: scroll to the bottom for an example of standard controller actions15.

Add/edit view filesHint: “find on page” “new.

html”, “index.

html”, etc.

to see examplesAnother hint: the form_for helperThat’s it!.Make sure you test your code as you go, and commit often.

.

. More details

Leave a Reply