views:

29

answers:

2

I'm using a inherited controller for an abstracted class. I'm trying to avoid overriding actions within all of the descendant controllers. How could I find out the name of the key where the array of form values is living? For example:

The master class currently uses this to update rows

if @parent.update_attributes(params[:parent])

Every class that inherits from it has its own name that will not be recognized

<input type="text" value="" name="child[title]" id="child_title">

How can I dynamically detect the :name I need to use in the params[ ] for each form? I would settle for some form_for guidance for my partial that handles edit and new:

form_for @parent do |f|

I've tried what is below but I can't get it to do PUT. When I edit it makes a new row:

form_for @child, :as => :parent, :url => child_path do |f|
A: 
cryo28
You pretty much understood what I was asking. What you suggested would work, but it is kind of fragile because I would have to maintain a hash of children. I need a method that would help me scrape the key of the array that is generated by a rails form. I am trying to do this so I don't have to use the :method => :put and :method => :post in two separate partials or repeat myself in controllers.
Octopus Inc
A: 

Thanks for nothing guys (save Cryo of course). I had the name of the key all along in my instance variable. I just didn't know how to get it out and turn it into the symbol I needed for the params hash. Here is how I did it:

@element.update_attributes(params[@element.class.name.downcase.to_sym])

This way I can make a resource, have it inherit from a parent controller, use the default form setup, and still recycle the logic from the parent controller.

Octopus Inc