Rails model associations and contollers/routes -
i have setup association have shows associated cities.
the relationship many shows 1 city.
i create new shows city
like such: mysite.com/cities/1/shows/new
i have setup models :
shows belongs_to :city city has_many :shows
how setup city controller new shows action? how setup routes.rb this?
i've figured out
in routes.rb
resources :cities resources :shows end
you use rule such :
match /cities/:id/shows/new => "shows#new"
and after, in new action in controller shows, preload city_id params[:id],
def new @show = show.new(:city_id => params[:id]) end
Comments
Post a Comment