Ah, so basically foo[#{a}][b] is nothing more but Ruby conventional 
syntax for
@params['foo']['#{a}][b]

As for my other question...I think I understand it now, but I want to be 
sure and clarify something.

def update
     @person = Person.find(@params["person"]["id"])

     @person.attributes = @params["person"]

     if @person.save
       redirect_to :action => "show", :id => @person.id
     else
       render "person/edit"

     end
end

     @person = Person.find(@params["person"]["id"])

@params["person"]["id"] could be person[#{id}].  Of course, Person.find 
is used because it will return a person record with the corresponding 
id.

I am assuming that since Ruby can go from singular to plural,  it is 
smart enough to know that People.find wants a single record that can 
only be found in the people db (as People represents multiple persons).

Frederick Cheung wrote:
> On 23 Sep 2008, at 21:17, Dave Lenhardt wrote:
>>
>>
>> What, exactly, is the [phone] in phones[#{phone.id][phone]?  I know
>> phones is the db phones.  I know phone id is the PK (and for
>> phones[new][phone].  What is phone though? Also,  in phones[new] 
>> [phone],
>> what is new creating/doing?
>>
> This is Rails parameter naming converion
> 
> phones[#{phone.id}][phone] means that the corresponding input element
> will (in the controller) be at params['phones']['25']['phone']
> (assuming the id was 25).
> 
> The 'new' is presumably just a convention by whoever wrote this code
> to indicate a new record.
> 
> I wrote some stuff up about this: 
> http://www.spacevatican.org/2008/7/18/parametrised-to-the-max
>>       render "person/edit"
>>
>>     end
>> end
> 
>> What is ["person"]?  What is it referencing?
>>
> 
> Not sure what you're asking about. params is just a regular hash,
> they're pulling out the value with key "person"

-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to