Skip to content

Instantly share code, notes, and snippets.

@alksl
Created May 14, 2014 18:15
Show Gist options
  • Save alksl/b4309f9cacc97cb74435 to your computer and use it in GitHub Desktop.
Save alksl/b4309f9cacc97cb74435 to your computer and use it in GitHub Desktop.
$ rails new vinylcollections
$ cd vinylcollections
$ git init
$ tmux new -s rails_demo
tmux: C-b C-c
$ rails server
show
$ rails g controller welcome index
routes.rb: root "welcome#index"
show
Gemfile: gem 'bootstrap-sass', '~> 3.1.1'
$ bundle update
application.css: *= require bootstrap
restart server
$ cp ~/prep/application.html.erb app/views/layouts/application.html.erb
show
$ cp ~/prep/superhero.css vendor/assets/stylesheets/superhero.css
show
$ cp ~/prep/welcome/index.html.erb app/views/welcome/index.html.erb
show
routes.rb: resources :collections
$ rake routes
show
explain layouts
explain yield
Domänmodell!!
$ rails g model Collection name:string
$ rails g model Issue artist:string title:string cover_url:string
$ rails g moder CollectionItem collection:references issue:references
visa migration script
vim db/*.rb
vim app/models/*.rb
collection.rb: has_many :collection_items
collection.rb: has_many :issues, through: :collection_items
$ rake db:migrate
$ cp ~/prep/seeds.rb db/seeds.rb
$ cp ~/prep/seed_data.json .
$ rake db:seed
$ rails console
Visa ActiveRecord
>Issues.all
>Collection.create!(name: "My awesome collection")
>c = Collection.find(1)
>c.issues
Gör controller
$ rails g controller collections
$ cp ~/prep/collections/new.html.erb app/views/collections/new.html.erb
$ cp ~/prep/collections/show.html.erb app/views/collections/show.html.erb
$cp ~/prep/collections/index.html.erb app/views/collections/index.html.erb
make the actions
routes.rb: recources :items (nested)
$ rake routes
$ rails g controller items
cp ~/prep/items/new.html.erb app/views/items/new.html.erb
make the actions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment