Skip to content

Instantly share code, notes, and snippets.

@sergii
Forked from thebucknerlife/rails_steps.md
Last active August 29, 2015 14:08
Show Gist options
  • Save sergii/bc9290f61824a1b93d61 to your computer and use it in GitHub Desktop.
Save sergii/bc9290f61824a1b93d61 to your computer and use it in GitHub Desktop.

Steps in creating a basic rails app

  1. Define your model(s)
  • What tables should exist in the database?
  • What fields should each table have?
  1. Define your associations
  • What are the relationships between your tables?
  1. Generate models
  2. Create your controllers
  3. Create your views
  • Your forms will go in here
  1. Define your routes
  • Consider using resources
  • Consider using nested resources
  • You can view your routes on your server at localhost:3000/rails/info/routes
  1. Steps for creating validations and displaying errors in the view
  • Add validation to your model
  • For example: validates_presence_of
  1. Within the else statement of your controller (in case it doesn't save)
  • Assign the errors to flash
  • For example flash[:danger] = model_name.errors.full_messages
  1. In your application's layout file (app/views/layout/application.html.erb), display your flash messages
  • For example:

    <% flash.keys.each do |f| %>
      <%= flash[f] %> 
    <% end %> 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment