During a load or save in my controller I''ve manually been doing:
@myobject = MyObject.find(:first, :conditions => "id =
#{@params[''id'']}")
If I''m updating an existing object I load it, change stuff using
something like myobject.name = "@params[''name'']",
etc etc, then call
save. That''s what I''ve done in similar situations for ages in
other
development languages. But, I had the urge to go back and look at
some of the online tutorials, where I noticed references like this:
<input type="hidden" id="myobject_id"
name="myobject[id]" value="<%@myobject.id %>"/>
So it appears as though Rails can automagically populate an object
which can then be referred to with something like:
@myobject = @params[''myobject'']
At least that''s what it SEEMS like. But if I define a select like:
<select name="myobject[id]">
.... code to loop through options setting value to myobject ids ...
</select>
I just have that, and a submit button. I have the @myobject
@params[''myobject''] in the resulting controller, but if I try
and view
@myobject.id in the view I get something like "-606936886" which is
definitely not valid.
Can rails load the object up for me or should I just go back to doing
the find() calls? Using myobject[property] to name inputs for calling
a scaffolded update() seems to work just fine.
I''d appreciate any little bit of info you may have.
Thanks!
- Brent