14. StreamsController should...
●
Index - show all streams
● New - show the form to create a stream
●
Create - take form data and saves a stream
● Destroy - delete a stream from the database
15. StreamsController should really...
●
Index - show all streams belonging to a station
● New - show the form to create a stream
belonging to a station
●
Create - take form data and saves a stream
belonging to a station
●
Destroy - delete a stream from the database
21. Answer: we're going to pass it in the url by
nesting resources
http://127.0.0.1:3000/stations/1/streams
We're going to tell the routes to interpret
this as :station_id
22. Answer: we're going to pass it in the url by
nesting resources
routes.rb:
get '/stations/:station_id/streams' =>
'streams#index'
23. Answer: we're going to pass it in the url by
nesting resources
routes.rb:
resources :stations
resources :streams
resources :stations do
resources :streams
end
24. Answer: we're going to pass it in the url by
nesting resources
routes.rb:
resources :stations
resources :streams
rake routes
resources :stations do
resources :streams
end
27. Nested Resources and Views
routes.rb:
resources :stations do
resources :streams
end
Generates url_helpers e.g.
station_streams_path(station)
station_stream_path(station, stream)
new_station_stream_path(station)
31. Nesting in Views: new.html.erb
<%= form_for @stream do |f| %>
Won't work as it does not include :station_id
32. Nesting in Views: new.html.erb
<%= form_for @stream do |f| %>
Won't work as it's path does not include :station_id
<%= form_for @stream, :url =>
station_streams_path(@station) do |f| %>
33. Connecting up the Views
Too many pages?
Create a partial called '_streams.html.erb'
This will be the same as index.html.erb
Include it in 'stations/show.html.erb':
<%= render :partial => “streams/streams”,
:locals => {:streams => @streams} %>