Czar.ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Aug-14 21:08 UTC
Catching data in model
Hello everybody, I am new to ruby on rails so please don''t laugh on my silly doubts. Problem : I am creating check boxes in rhtml file. All the items which are being checked, i am able to catch it in the controller class. but i am not being able to catch values from controller to model. supplier.rhtml file <%= check_box(''hotel_'', '''', {}, hotel.group_name+"^"+hotel.pid, '''') %></td> contoller class def supplier @temp = @params[''hotel_''] end I want to catch @temp in the concern model class...how can do that... thanks a lot in advance Czar --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You need to instantiate a new class object. Your not referencing your class at all, so none of your model methods are available to you unless your using an object of that class. So instead try something like:(NB not tested code) In your controller: def supplier @temp = Hotel.new(params[:hotel_]) end Then within that suppler method you''ll be able to use methods written in the Hotel class to manipulate that data, for instance if you have a method called say write_to_screen in your Hotel class class Hotel<ActiveRecord::Base def self.write_to_screen puts self.group_name end end then you could go @temp.write_to_screen and that would execute the method on that @temp instance variable, because @temp is an instance of the object Hotel, and Hotel is an instance of the object Class. Does that help? It''s Object Orientation 101, so it might be worth having a good read up on OOP, it''s help to get your head around that stuff. Cam On Aug 15, 7:08 am, "Czar.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <Czar.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello everybody, > I am new to ruby on rails so please don''t laugh on my silly doubts. > > Problem : > > I am creating check boxes in rhtml file. All the items which are being > checked, i am able to catch it in the controller class. but i am not > being able to catch values from controller to model. > > supplier.rhtml file > <%= check_box(''hotel_'', '''', {}, hotel.group_name+"^"+hotel.pid, '''') > %></td> > > contoller class > > def supplier > @temp = @params[''hotel_''] > end > > I want to catch @temp in the concern model class...how can do that... > > thanks a lot in advance > Czar--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---