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. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 2/12/07, Thushan <thushan.abeysekera-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks (again) George. That worked. On Feb 12, 5:15 pm, "George Ogata" <george.og...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 2/12/07, Thushan <thushan.abeysek...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > 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.--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
George Ogata wrote:> Hi Thushan, > > Try: > > @main_service.send("travel_service=", TravelService.new)That''s nice and all, but why on earth would you do this? @main_service.travel_service = TravelService.new seems much much simpler. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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). On Feb 12, 10:41 pm, Alex Wayne <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> George Ogata wrote: > > Hi Thushan, > > > Try: > > > @main_service.send("travel_service=", TravelService.new) > > That''s nice and all, but why on earth would you do this? > > @main_service.travel_service = TravelService.new > > seems much much simpler. > > -- > Posted viahttp://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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---