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
<%= self.class.superclass %> gives ActionView::Base.
self in a view is not calling the controller.
-Jatinder
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 S. [email protected] wrote:
On 8/10/07, [rob desbois] [email protected] wrote:
–
Rob Desbois
Eml: [email protected]
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.
Great thanks for that; I wasn’t aware you could create anonymous classes
in
Ruby.
–rob
On 8/10/07, Jatinder S. [email protected] wrote:
0x4864ecc>" - why doesn’t this class have a name?
“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: [email protected]
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.
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
Try <%= controller.inspect %>
On 8/10/07, [rob desbois] [email protected] wrote:
Am I right in thinking that ‘self’ in a view is the calling
controller?
Thanks for any help!
–rob
–
Cheers!
On 8/10/07, [rob desbois] [email protected] wrote:
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 O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com
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
–