#sxsw #makeitreal @starterleague
- Environment Setup
- Explore static mockup of portfolio app
- Dive into Rails
- Live deploy
- Bring the mockup to life
- Optional: Ruby Basics
- Finish up the portfolio app
- Build a Facebook app
- Office hours
Welcome! For the workshop today, everyone will be working in pairs (we find working in pairs greatly enhances learning, and also, it's just a lot more fun).
Just so that we are all on the same page, we are going to stick with Macs. If you don't have a Mac, find someone who does to pair up with :)
If you haven't already tried installing Rails on your system, visit RailsInstaller.org, download the appropriate package, and run it.
If you have already tried to install Ruby and Rails on your system, launch the Terminal app and enter the following at the prompt:
ruby -v(You should seeruby 1.9.3)rails -v(You should seeRails 3.2.12)git --version(You should seegit version 1.8.1.1)
If your Ruby and Git are alright but you don't have Rails, gem install rails (or if you have Rails but it is an older version, gem update rails).
If you see something different, visit RailsInstaller, download the appropriate package, and run it. Then try the above commands again. If you have any problems, let one of us know!
You should also download and install Sublime Text 2 (they offer a free trial).
pwdDisplay your current locationlsList the contents of the current foldermkdir <folder name>Create a subfoldercd ~Navigate to your Home foldercd <folder name>Navigate into a subfoldercd ..Navigate back to the parent folderopen .Open the current folder in Finder
cd ~Navigate to your home foldermkdir devCreate a subfolder calleddevcd devNavigate into~/devmkdir sxswcd sxsw
- Go to the GitHub repository for our mockup and click the Download Zip button. Extract the archive into your working folder.
- Open
portfolio.htmlandportfolio-item.htmland check 'em out. This is the app we're going to bring to life.
rails new firstappCreate a new appcd firstappNavigate into your apprails serverStart your web server- Open up
http://localhost:3000/in Chrome to make sure the web server is up and running. - Drag your static mockup into your app's
publicfolder and open uphttp://localhost:3000/portfolio.htmlin Chrome.
- Get Started with Heroku
- Open your app's
Gemfile - Change
gem 'sqlite3'
to
group :development do
gem 'sqlite3'
end
and add
group :production do
gem 'pg'
end
- From the command line,
bundle install git initInitialize a local Git repositorygit add -AAdd all of the files in the current folder to a version staging areagit commit -m 'Brand new app with static mockup'Describe and save the current version of the codeheroku create sxsw-portfolioCreate a repository for our code in Heroku's cloudgit push heroku masterSend our code to Heroku for deploymentheroku run rake db:migrateCreate any database tables we need on Heroku's serverheroku openOpen our live app
- At the heart of every app is data; things that the app keeps track of, and presents to the user in a valuable way.
- To store all this data, we typically use databases. A database is simply a set of tables.
- We refer to these things as resources. Pretty much every app you can think of is a collection of resources that you can Create, Read, Update, and/or Delete.
- As such, Rails gives us a handy tool to get a head start on building a CRUD resource.
rails generate scaffold <table name (singular)> <first column>:<datatype> <second column>:<datatype> …Get a headstart on building a database-backed web resourcerake db:migrateCreate the actual table in your database- Open
http://localhost:3000/<table name (plural)>in Chrome
- Place all CSS files into
app/assets/stylesheets - Place all JavaScript files into
app/assets/javascripts - Place all image files into
app/assets/images - CSS and JavaScript will be automatically included in all of the pages served by the app.
- Images can be located at
http://localhost:3000/assets/<filename> - Delete the
app/stylesheets/scaffolds.css.scssfile.
- Navigate to
~/dev/sxswin Terminal git clone https://github.com/tsl-sxsw/portfolioDownload the code and version historycd portfolioNavigate into the repositorygit checkout v2Jump back to the first versionbundle installInstall all the libraries that the app needsrake db:migrateCreate your database and tablesrake db:seedPre-populates database with dummy datarails serverStart the server (don't forget to quit any other running servers with CTRL-C)
- Open up a new Terminal tab with CMD-T and make sure you are in the app's folder
git add -ACollect the changes you made to the code since the last saved versiongit stashThrow them all awaygit checkout v2Jump to the right version
- Your HTML templates are located in the
app/views/<table name (plural)>folder. - View templates are standard HTML with a bit of Ruby sprinkled in.
- Ruby goes in special Embedded Ruby Tags, <%= %>
- Check out
app/views/projects/show.html.erb. What's the pattern for accessing data from the database? - Try to enhance the HTML around the ERB to look more like our mockup.
- You need not include
<html>,<head>, or<body>tags in the view template; Rails will automatically include them. Just include the content of the body. - First just paste the static markup into the view template; then try to go through, line by line, and embed Ruby wherever you need to in order to make it dynamic.
- One possible solution can be seen here -- don't look at it until you've finished!
- If you want to sync up,
git add -A,git stash,git checkout v3 - Enhance the index view template to look like our mockup.
- Hint: every table automatically gets a column called
id. The URL for the show page of a particular project is/projects/<that project's ID number>. - One possible solution can be seen here -- don't look at it until you've finished!
- If you want to sync up,
git add -A,git stash,git checkout v4 - In the
app/controllers/projects_controller.rbfile, add the linehttp_basic_authenticate_with :name => "jeff", :password => "hockey", :except => [:index, :show]on line 2 - This will require authentication for every action except index (see the list of all projects) and show (see the details of one project).
- In particular, visitors will not be able to Create, Update, or Destroy projects. They can only Read.
- If you want to sync up,
git add -A,git stash,git checkout v5 - Add another database-backed resource, Inquiry. The inquiries table should store name (string), email (string), and message (text). Solution
- Add a link in the nav bar to a page that allows visitors to submit inquiries. Solution
- Lock down access to everything Inquiry-related except the new and create actions. Solution
If you enjoyed the workshop, or if you didn't, SXSW encourages you to rate us at sxsw.tv/ck8.
Please stay in touch with us; we'd love to see the beautiful things you build.