Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Welcome To The Jungle

Welcome To The Jungle

An overview of the file structure of a rails application

Kurtis Rainbolt-Greene

March 14, 2012
Tweet

More Decks by Kurtis Rainbolt-Greene

Other Decks in Programming

Transcript

  1. Rails.root • Rails.root is the root of the application directory

    • It contains 3 major parts: ◦ Logic: app/, lib/, & config/ ◦ Tools: Gemfile, Gemfile.lock, Rakefile, config.ru, scripts/, db/ ◦ Testing: spec/, test/, features/ • This is where you run your commands, like `rails` or `rake`
  2. The app directory • The app directory is where the

    important application logic is at • It normally contains: ◦ controllers/ ◦ models/ ◦ helpers/ ◦ mailers/ ◦ assets/ ◦ views/ • These will be covered in the following classes
  3. The config directory • The config directory is where all

    of our "setup" code is • It contains things like: ◦ Initializers - Logic that runs at the start of your rails application ◦ Environment logic - Logic that runs depending on your environment type ◦ Settings - Configurations for various external parts of rails, like databases • Changing any of these requires a restart of the application
  4. The lib directory • The lib directory is a catch

    all place for the rest of your application logic • You can put various changes to Rails in here • These are also loaded at the start of Rails • You probably wont mess with these
  5. The Gemfile && Gemfile.lock • The Gemfile is a list

    of all the gems you'll be using • It also groups the gems into specific environments • It also helps you download the gems you need for your application • The lock file is simply an organized list of dependencies • Don't edit it, it's auto generated
  6. Rakefile • The Rakefile lets you use the `rake` command

    • The `rake -T` command shows you all of the possible tasks • Run: `rake -T` • Important rake tasks are: ◦ rake routes - Shows a list of routes ◦ rake db:migrate - For SQL databases ◦ rake db:create - Mostly for SQL databases
  7. The db directory • This is where migrations are kept

    (for sql databases) • This is also where the schema.rb file is kept (for sql databases) • The seed.rb file is also here, and that's where we can build up some data
  8. The scripts directory • Here you can keep all sorts

    of custom scripts that do neat things • It's also where the default rails script is • Largely not used, unless you need to do special things for your app
  9. Testing your rails application • Testing is the practice of

    writing checks to make sure your program is working correctly • There are generally two types of testing practices: ◦ Behavior ◦ Unit • There are libraries that have strengths in each: ◦ Rspec is good at behavior testing ◦ Minitest is good at unit testing • We will only cover some basics
  10. Starting the server • First install dependencies with `bundle install`

    • To start your server run: `rails server` • This starts up a local server for your application • You can now access the site at http: //localhost:3000 • No one else can go to this, without you turning some things on • This is the default page of all rails applications