wbsurfver-/E1597aS9LQAvxtiuMwx3w@public.gmane.org
2009-Mar-25 20:57 UTC
curious how params, flash etc work in rails ?
I am curious how stuff like params and flash work in the controller ? Typically an instance variable is something like @params, or maybe self.params. How does rails make params appear as if it''s an instance variable ? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> I am curious how stuff like params and flash work in the controller ? > Typically an instance variable is something like > @params, or maybe self.params. How does rails make params appear as if > it''s an instance variable ?I believe at one point params was an instance variable. And there was a method "params" that passed through to that instance. I also remember that this was changed awhile back and you should never ever use @params again. That it is no longer a simple instance variable. As for how they work specifically, dig through the source :) --~--~---------~--~----~------------~-------~--~----~ 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 Wed, Mar 25, 2009 at 3:57 PM, wbsurfver-/E1597aS9LQAvxtiuMwx3w@public.gmane.org <wbsurfver-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am curious how stuff like params and flash work in the controller ? > Typically an instance variable is something like > @params, or maybe self.params. How does rails make params appear as if > it''s an instance variable ?> irb >> o = Object.new=> #<Object:0xb7a3e000>>> o.instance_variable_set( :@foo, ''bar'' )=> "bar">> o.inspect=> "#<Object:0xb7a3e000 @foo="bar">">>http://www.ruby-doc.org/core/classes/Object.html#M000381 -- Greg Donald http://destiney.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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 25, 8:57 pm, "wbsurf...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org" <wbsurf...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am curious how stuff like params and flash work in the controller ? > Typically an instance variable is something like > @params, or maybe self.params@params is an instance variable, but self.params is a method called params> How does rails make params appear as if > it''s an instance variable ?it doesn''t. It just defines a method called params (and one called flash etc...) on controllers. There use to be instance variables called @params, @flash that you could use interchangeably but use of those was deprecated and removed a while back. Fred --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ok, offhand I''m not sure how to create a method foo that is used like an array so I can say foo[:id], but I''ll have to think about that or look through my books ... On Mar 25, 5:46 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mar 25, 8:57 pm, "wbsurf...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org" <wbsurf...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I am curious how stuff like params and flash work in the controller ? > > Typically an instance variable is something like > > @params, or maybe self.params > > @params is an instance variable, but self.params is a method called > params > > > How does rails make params appear as if > > it''s an instance variable ? > > it doesn''t. It just defines a method called params (and one called > flash etc...) on controllers. There use to be instance variables > called @params, @flash that you could use interchangeably but use of > those was deprecated and removed a while back. > > Fred--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 25, 10:07 pm, Larz <wbsurf...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> ok, > > offhand I''m not sure how to create a method foo that is used like an > array so I can say foo[:id], but I''ll have to think about that or look > through my books ... >There''s not much to it: class Foo def initialize @hash = {} end def [](key) @hash[key] end def []=(key,value) @hash[key]=value end end That''s not what''s happening with params though. That''s just a method that returns a hash. Fred> On Mar 25, 5:46 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On Mar 25, 8:57 pm, "wbsurf...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org" <wbsurf...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I am curious how stuff like params and flash work in the controller ? > > > Typically an instance variable is something like > > > @params, or maybe self.params > > > @params is an instance variable, but self.params is a method called > > params > > > > How does rails make params appear as if > > > it''s an instance variable ? > > > it doesn''t. It just defines a method called params (and one called > > flash etc...) on controllers. There use to be instance variables > > called @params, @flash that you could use interchangeably but use of > > those was deprecated and removed a while back. > > > Fred--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---