Skip to content
zurbergram edited this page Oct 23, 2014 · 2 revisions

Introduction

  • What is an application?
  • Ruby, RubyonRails, Javascript
  • Model-View-Controller (MVC)
  • What is Open Source?
  • 4-week plan

##Pre-requisites

Create Application

  • rails new sw_devcamp
  • cd sw_devcamp
  • For Linux boxes, add to \Gemfile:
    • uncomment:gem 'therubyracer', platforms: :ruby
    • bundle install (installs javascript support)
  • rails s => Starts the Rails Web Server
  • open browser, go to http://localhost:3000
  • Play!
  • press <control>-c whhen done

Create the Events form (Model)

  • rails shortcuts - scaffolds
  • builds model, view, controller, and tests
  • Our first Model: Event
  • Meetings, Bootcamps, Camp
  • What Fields do we want?
  • rails generate scaffold Event name:string description:text start_time:datetime end_time:datetime location:text
  • setup the database: rake db:migrate
  • restart the web server: rails s
  • open browser, go to http://localhost:3000/events
  • Play!
  • press <control>-c when done

setup our default site:

We want to see what events are available when we bring up the site

  • open sublime text and do File - Open: config/routes.rb
  • add root to: "events#index"
  • run rails s
  • open browser, go to http://localhost:3000
  • Play!
  • press <control>-c when done

Prettify it

  • Zurb Foundation
  • add to Gemfile: gem 'foundation-rails'
  • download it from the internet: 'bundle install'
  • set it up: rails g foundation:install
  • run rails s
  • open browser, go to http://localhost:3000
  • Play!
  • press <control>-c when done

Adding Users

  • Rails Gems
  • https://github.com/plataformatec/devise: User management
  • add to Gemfile: gem 'devise'
  • dowload and install it: bundle install
  • run rails generate devise:install
  • Create the User form:
  • run rails generate devise User
  • add User to the database rake db:migrate
  • setup so we can e-mail:
  • edit config/environments/development.rb
  • add the line: config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
  • add a place for error messages:
  • edit app/views/layouts/application.html.erb and add after the <body> tag:
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
    <% if current_user %>
      <%= link_to 'Log Out', destroy_user_session_path, :method => :delete  %>
    <% end %>
  • Register a user:
  • run rails s
  • open browser, go to http://localhost:3000/users/sign_up
  • create a user
  • And now let's keep people from accessing events:
  • add before_action :authenticate_user! to /app/controllers/events_controller.rb
  • run rails s
  • open browser, go to http://localhost:3000
  • Play!
  • press <control>-c when done

Next Week: Making it pretty!

References & Homework

Clone this wiki locally