12. Controllers and Models
Models Controllers
DB
In stations_controller.rb (index):
@stations = Station.all
13. Controllers and Models
Models Controllers
DB
In stations_controller.rb (show):
@stations = Station.find(params[:id])
14. Controllers and Models
Models Controllers
DB
ActiveRecord::Base
Maps station model to stations table in database
15. The Rails Console
1. Open the terminal
2. Navigate to the 'firstfm' directory
3. Run the commands:
rails console
@stations = Station.all
16. The Rails Console
rails console
@stations = Station.all
Task!
Recreate the first line of the show action.
1. Create a hash with the key :id
2. Pass it into Station.find()
Go to
guides.rubyonrails.org/active_record_querying.html
17. The Rails Console
Recreate the first line of the show action.
1. Create a hash with the key :id
2. Pass it into Station.find()
Try out other AR methods:
guides.rubyonrails.org/active_record_querying.html
apidock.com/rails/ActiveRecord/Base
18. Views
Models Controllers
DB
@station = Station.find(params[:id])
19. Views
Views
Models Controllers
DB
@station = Station.find(params[:id])
20. Views
Views
Models Controllers
DB
respond_to do |format|
format.html # index.html.erb
format.json {render json: @stations }
end
37. Task: Display a logo image on each
page !
1. Find and download an image to use as
a logo
2. Put it in 'firstfm/public/assets/'
3. Display it with the 'image_tag' helper
Search for 'image_tag' on
http://apidock.com/rails for reference!
38. Web Browser
How does it
all fit together?
Rails
Routing System
Views
Models
DB Controllers