Hi all, very much new to Ruby and RoR - a very steep learning curve but exciting stuff! I''m just playing around with some things - I have a LoginController which has an index.rhtml view file. If I insert <%= self.inspect %> into this I get LOADS of not-very-readable stuff, so I tried <%self.class %> but this just gives me something like "#<Class: 0x4864ecc>" - why doesn''t this class have a name? Am I right in thinking that ''self'' in a view is the calling controller? Thanks for any help! --rob --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
<%= self.class.superclass %> gives ActionView::Base. self in a view is not calling the controller. -Jatinder On 8/10/07, [rob desbois] <rob.desbois-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Hi all, very much new to Ruby and RoR - a very steep learning curve > but exciting stuff! > > I''m just playing around with some things - I have a LoginController > which has an index.rhtml view file. If I insert <%= self.inspect %> > into this I get LOADS of not-very-readable stuff, so I tried <%> self.class %> but this just gives me something like "#<Class: > 0x4864ecc>" - why doesn''t this class have a name? > > Am I right in thinking that ''self'' in a view is the calling > controller? > > Thanks for any help! > --rob > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 Jatinder, That makes more sense for it to be a view object. Do you know why the actual class seems to have no name? --rob On 8/10/07, Jatinder Singh <jatinder.saundh-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > <%= self.class.superclass %> gives ActionView::Base. > > self in a view is not calling the controller. > > > -Jatinder > > > > On 8/10/07, [rob desbois] <rob.desbois-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Hi all, very much new to Ruby and RoR - a very steep learning curve > > but exciting stuff! > > > > I''m just playing around with some things - I have a LoginController > > which has an index.rhtml view file. If I insert <%= self.inspect %> > > into this I get LOADS of not-very-readable stuff, so I tried <%> > self.class %> but this just gives me something like "#<Class: > > 0x4864ecc>" - why doesn''t this class have a name? > > > > Am I right in thinking that ''self'' in a view is the calling > > controller? > > > > Thanks for any help! > > --rob > > > > > > > > > > > > > >-- Rob Desbois Eml: rob.desbois-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Tel: 01452 760631 Mob: 07946 705987 "There''s a whale there''s a whale there''s a whale fish" he cried, and the whale was in full view. ...Then ooh welcome. Ahhh. Ooh mug welcome. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
No clue about the thought behind the actual class having no name. Following is a snippet from actionpack-1.13.3\lib\action_controller/base.rb http://pastie.caboo.se/86581 view_class(extending ActionView:Base) gets associated with a controller. -Jatinder On 8/10/07, Rob Desbois <rob.desbois-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Thanks Jatinder, > > That makes more sense for it to be a view object. > Do you know why the actual class seems to have no name? > > --rob > > On 8/10/07, Jatinder Singh <jatinder.saundh-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > <%= self.class.superclass %> gives ActionView::Base. > > > > self in a view is not calling the controller. > > > > > > -Jatinder > > > > > > > > On 8/10/07, [rob desbois] <rob.desbois-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > Hi all, very much new to Ruby and RoR - a very steep learning curve > > > but exciting stuff! > > > > > > I''m just playing around with some things - I have a LoginController > > > which has an index.rhtml view file. If I insert <%= self.inspect %> > > > into this I get LOADS of not-very-readable stuff, so I tried <%> > > self.class %> but this just gives me something like "#<Class: > > > 0x4864ecc>" - why doesn''t this class have a name? > > > > > > Am I right in thinking that ''self'' in a view is the calling > > > controller? > > > > > > Thanks for any help! > > > --rob > > > > > > > > > > > > > > > > > > > > > > > > -- > Rob Desbois > Eml: rob.desbois-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > Tel: 01452 760631 > Mob: 07946 705987 > "There''s a whale there''s a whale there''s a whale fish" he cried, and the > whale was in full view. > ...Then ooh welcome. Ahhh. Ooh mug welcome. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Great thanks for that; I wasn''t aware you could create anonymous classes in Ruby. --rob On 8/10/07, Jatinder Singh <jatinder.saundh-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > No clue about the thought behind the actual class having no name. > > Following is a snippet from > actionpack-1.13.3\lib\action_controller/base.rb > http://pastie.caboo.se/86581 > > view_class(extending ActionView:Base) gets associated with a controller. > > > > -Jatinder > > On 8/10/07, Rob Desbois < rob.desbois-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Thanks Jatinder, > > > > That makes more sense for it to be a view object. > > Do you know why the actual class seems to have no name? > > > > --rob > > > > On 8/10/07, Jatinder Singh <jatinder.saundh-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > <%= self.class.superclass %> gives ActionView::Base. > > > > > > self in a view is not calling the controller. > > > > > > > > > -Jatinder > > > > > > > > > > > > On 8/10/07, [rob desbois] <rob.desbois-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > > > > Hi all, very much new to Ruby and RoR - a very steep learning curve > > > > but exciting stuff! > > > > > > > > I''m just playing around with some things - I have a LoginController > > > > which has an index.rhtml view file. If I insert <%= self.inspect %> > > > > into this I get LOADS of not-very-readable stuff, so I tried <%> > > > self.class %> but this just gives me something like "#<Class: > > > > 0x4864ecc>" - why doesn''t this class have a name? > > > > > > > > Am I right in thinking that ''self'' in a view is the calling > > > > controller? > > > > > > > > Thanks for any help! > > > > --rob > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > Rob Desbois > > Eml: rob.desbois-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > > Tel: 01452 760631 > > Mob: 07946 705987 > > "There''s a whale there''s a whale there''s a whale fish" he cried, and the > > whale was in full view. > > ...Then ooh welcome. Ahhh. Ooh mug welcome. > > > > > > > >-- Rob Desbois Eml: rob.desbois-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Tel: 01452 760631 Mob: 07946 705987 "There''s a whale there''s a whale there''s a whale fish" he cried, and the whale was in full view. ...Then ooh welcome. Ahhh. Ooh mug welcome. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Try <%= controller.inspect %> On 8/10/07, [rob desbois] <rob.desbois-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi all, very much new to Ruby and RoR - a very steep learning curve > but exciting stuff! > > I''m just playing around with some things - I have a LoginController > which has an index.rhtml view file. If I insert <%= self.inspect %> > into this I get LOADS of not-very-readable stuff, so I tried <%> self.class %> but this just gives me something like "#<Class: > 0x4864ecc>" - why doesn''t this class have a name? > > Am I right in thinking that ''self'' in a view is the calling > controller? > > Thanks for any help! > --rob > > > > >-- Cheers! - Pratik http://m.onkey.org --~--~---------~--~----~------------~-------~--~----~ 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 8/10/07, [rob desbois] <rob.desbois-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi all, very much new to Ruby and RoR - a very steep learning curve > but exciting stuff! > > I''m just playing around with some things - I have a LoginController > which has an index.rhtml view file. If I insert <%= self.inspect %> > into this I get LOADS of not-very-readable stuff, so I tried <%> self.class %> but this just gives me something like "#<Class: > 0x4864ecc>" - why doesn''t this class have a name? > > Am I right in thinking that ''self'' in a view is the calling > controller?self.inspect is probably inspecting things like the request, response, and controller objects. There may be some duplication, because controller.inspect probably shows the request and response objects too. The view classes are created dynamically with the necessary helpers mixed in. http://dev.rubyonrails.org/browser/tags/rel_1-2-3/actionpack/lib/action_controller/base.rb#L1028 -- Rick Olson http://lighthouseapp.com http://weblog.techno-weenie.net http://mephistoblog.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 -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2007-Aug-10 13:07 UTC
Re: self.class in view rhtml
Hi -- On Fri, 10 Aug 2007, Rob Desbois wrote:> Thanks Jatinder, > > That makes more sense for it to be a view object.Of course, that raises the question: how can this view object share instance variables with the controller object, since instance variables by definition are always the property of self, and there are two different selfs here? I know you didn''t ask, but the answer is kind of interesting :-) The controller''s instance variables have to be explicitly transferred to the view: def assign_variables_from_controller @assigns.each { |key, value| instance_variable_set("@#{key}", value) } end where @assigns is the controller''s instance variables. So the whole thing where, say, @user is "shared" between the controller and the view is based on this sleight of hand. It''s almost the opposite of what instance variables, as such, are actually for, but it provides a very nice sense of continuity and connection between the controller code and the view. David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.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 -~----------~----~----~----~------~----~------~--~---