Skip to content

Instantly share code, notes, and snippets.

@mhenke
Last active December 11, 2015 21:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mhenke/4660590 to your computer and use it in GitHub Desktop.
Save mhenke/4660590 to your computer and use it in GitHub Desktop.

Description

We build an entire Rails application from scratch, showing you every single step in the process. http://www.codeschool.com/code_tv/rails-app-from-scratch-part-1

Initializing app

Create new app

$ rails new wandrr -d postgresql
$ cd wandrr
$ git init
$ git add .
$ git commit -m "new rails app"

Add twiter-bootstrap to Gemfile

gem 'twitter-bootstrap-rails'

Install gem

$ bundle install 

Install and Create layout

https://github.com/seyhunak/twitter-bootstrap-rails

$ rails g bootstrap:install 
$ rails g bootstrap:layout application
$ git add .
$ git commit -m "adding twitter bootstrap"

Create Model

$ rails g scaffold trip name:string description:text
$ rake db:create
$ rake db:migrate
$ rails server

Commit scaffolding code

$ git add .
$ git commit -m "adding twitter bootstrap"

Adding home route to routes.rb

root to: 'trips#index'

Don't forget to delete index.html in the public folder. Then restart server.

Simple styling with bootstrap

Improve table look

Head into trips/index.html.erb and add class="table" to the table tag

$ git add -u
$ git commit -m "Root to trips and fix table"

http://twitter.github.com/bootstrap/base-css.html#tables

Associations & Nested Routes

Creating Destination route

$ rails g scaffold Destination name:string description:text

Add to models/trip.rb $ has_many :destinations

Add to models/destination.rb $ belongs_to :trip

Add trip_id to destination $ rails g migration add_trip_id_to_destinations trip_id:integer $ rake db:migrate

Add destination roote under trips in config/routes. resources :trips do resources :destinations end

nesting views & forms

Add link for new destination in trips/show.html.erb

<p>
  <%= link_to 'New Destination', new_trip_destination_path(@trip) %>
</p>

Modify controllers/destination_controller.rb in the new method

@trip = Trip.find(params[:trip_id])

Modify (@destination) in views/destinations/_form.html.erb

[@trip, @destination]

Modify the controllers/destinations_controller.rb

create method

Change: @destination = Destination.new(params[:destination])

To: @trip = Trip.find(params[:trip_id]) @destination = trip.destinations.new(params[:destination])

edit method

Add: @trip = Trip.find(params[:trip_id])

bug fixes & improvements

validations

code challenge

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment