2 ms·
As for (2), yes you can. Let's say you have a form that lets you update the status of your cat and your dog: # config/routes.rb map.resource :pets, :m
by erikpukinskis 16y ago
As for (2), yes you can. Let's say you have a form that lets you update the status of your cat and your dog:
# config/routes.rb
map.resource :pets, :member => [:show, :update]
# app/views/pets/status.html.haml
- form_tag update_pets_path do
.cat_fields
- fields_for @cat do |f|
= f.text_field :status
= submit_tag
.dog_fields
- fields_for @dog do |f|
= f.text_field :status
= submit_tag
# app/controllers/pets_controller.rb
def show
@cat = Pet.find_by_species("cat")
@dog = Pet.find_by_species("dog")
end
def update
["cat", "dog"].each do |species|
pet = Pet.find_by_species(species)
pet.update_attributes(params[species])
end
end