Thushan
(Thushan)
February 12, 2007, 12:07pm
1
I have the following models:
class MainService < ActiveRecord::Base
has_one :travel_service
end
class TravelService < ActiveRecord::Base
belongs_to :main_service
end
I can use the following:
@main_service.travel_service = TravelService.new
But I can't use the following:
@main_service.send ("travel_service") = TravelService.new
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.
George1
(George)
February 12, 2007, 12:15pm
2
But I can't use the following:
@main_service.send ("travel_service") = TravelService.new
It says " unexpected '=', expecting $ "
Hi Thushan,
Try:
@main_service.send ("travel_service=", TravelService.new)
#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
TravelService.new as an argument.
Thanks in advance for any help.
'Welcome!
George.
Thushan
(Thushan)
February 12, 2007, 2:56pm
3
Thanks (again) George. That worked.
Thushan
(Thushan)
February 13, 2007, 4:40pm
4
Actually, what I want is this:
@main_service.send (service_type, TravelService.new)
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).