[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Model Commands

Mariko C.

2/29/2008 9:02:00 PM

I'd like to do something like this in my RoR code:


name = "james"
box = Box.find(1)
box_name = box.name

Where "james" is an existing column in table Box. I try to do this but
RoR tells me "undefined method `name' for #<Box:0x333a81c>". Is it
possible to get around this? Basically what I have is a list of strings
that I need to use as column commands.

Thanks in advance for any help.
--
Posted via http://www.ruby-....

2 Answers

Florian Gilcher

2/29/2008 9:09:00 PM

0


On Feb 29, 2008, at 10:01 PM, Mariko C. wrote:

> I'd like to do something like this in my RoR code:
>
>
> name = "james"
> box = Box.find(1)
> box_name = box.name
>
> Where "james" is an existing column in table Box. I try to do this but
> RoR tells me "undefined method `name' for #<Box:0x333a81c>". Is it
> possible to get around this? Basically what I have is a list of
> strings
> that I need to use as column commands.
>
> Thanks in advance for any help.
> --
> Posted via http://www.ruby-....
>

You want to send a message with to the method "james". What you are
doing is sending a message to the method "name".

What you want to do is:

=== code ===

name = "james"
box = Box.find(1)
box_name = box.send(name)

=== code ===

I don't know what you want to acomplish, but this is how it works.

Greetings
Florian Gilcher



Mariko C.

2/29/2008 9:30:00 PM

0

That works perfectly. Many thanks for your quick response!
--
Posted via http://www.ruby-....