Forum: Ruby on Rails Proper use of "send" method

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
C74685ae6ef6515345f651802f37f3ac?d=identicon&s=25 Thushan (Guest)
on 2007-02-12 13:07
(Received via mailing list)
I have the following models:

class MainService < ActiveRecord::Base
  has_one :travel_service

class TravelService < ActiveRecord::Base
  belongs_to :main_service

I can use the following:

@main_service.travel_service =

But I can't use the following:
@main_service.send("travel_service") =

It says " unexpected '=', expecting $ "

What's the correct way of using the "send" method?
(I think this is mainly due to my bad ruby knowledge :( )

Thanks in advance for any help.
C515daf003a781a638d8a01e41a935a0?d=identicon&s=25 George Ogata (Guest)
on 2007-02-12 13:16
(Received via mailing list)
On 2/12/07, Thushan <> wrote:
> But I can't use the following:
> @main_service.send("travel_service") =
> It says " unexpected '=', expecting $ "

Hi Thushan,



#send is a plain old method, and can't be called on the LHS of an
assignment.  The method you want to send is "travel_service=", with as an argument.

> Thanks in advance for any help.

C74685ae6ef6515345f651802f37f3ac?d=identicon&s=25 Thushan (Guest)
on 2007-02-12 15:57
(Received via mailing list)
Thanks (again) George. That worked.
D0cd6b10e01bacb976b3b815a9c660bc?d=identicon&s=25 Alex Wayne (squeegy)
on 2007-02-12 18:41
George Ogata wrote:
> Hi Thushan,
> Try:
>   @main_service.send("travel_service=",

That's nice and all, but why on earth would you do this?

  @main_service.travel_service =

seems much much simpler.
C74685ae6ef6515345f651802f37f3ac?d=identicon&s=25 Thushan (Guest)
on 2007-02-13 17:41
(Received via mailing list)
Actually, what I want is this:


Where service_type may contain sevral other service types (including
travel_service). All those service types belongs_to MainService (and
MainService has_one of each of them).

On Feb 12, 10:41 pm, Alex Wayne <>
This topic is locked and can not be replied to.