Correcting context when passing attributes on tags

33 views
Skip to first unread message

Tim Griffin

unread,
Jan 12, 2014, 10:32:10 AM1/12/14
to hobo...@googlegroups.com
Hi all,

This may seem really basic, but it tripped me up for a while because I'd forgotten a basic Hobo tenet: Always be aware of context.
 
I'd defined a tag that calls another custom tag as follows:

<def tag="plans" attrs="showspecialcontrols">
  <my-table-plus:plans fields="plan_no, plan_type" showmycontrols="&showspecialcontrols">
  ...
</def>


But, for the longest time, the highlighted attribute call generated:

undefined method `showspecialcontrols' for #<#<Class:...

It took me a while to realize/remember that by including "plans" in my call to <my-table-plus:> I'd shifted the context for the attribute I'd passed in. Hobo was now looking for a showspecialcontrols method on a plan, which didn't exist. 

Unless someone can contribute an alternate solution, I couldn't see a way around this without assigning the showspecialcontrols attribute to an instance variable:

<def tag="plans" attrs="showspecialcontrols">

   <!-- We need an instance variable here otherwise context is confused within call to my-table-plus -->
   <% @show = showspecialcontrols %>

   <my-table-plus:plans fields="..." showmycontrols="&@show">


Tim





Ignacio Huerta

unread,
Jan 12, 2014, 2:01:43 PM1/12/14
to hobo...@googlegroups.com
Hi Tim,

I wanted to reproduce this to see if I could come up with a different
solution, but I haven't been capable of reproducing it :P.

This is my test code, I must have missed something important :)

<plans showspecialcontrols="false"/>

<def tag="plans" attrs="showspecialcontrols">
<my-table-plus:postulantes showmycontrols="&showspecialcontrols"/>
</def>

<def tag="my-table-plus" attrs="showmycontrols">
showmycontrols: <%= showmycontrols.inspect %>
this: <%= this.inspect %>
<table-plus fields="this"/>
</def>

Warm regards,
Ignacio

El 12/01/14 16:32, Tim Griffin escribi�:
> Hi all,
>
> This may seem really basic, but it tripped me up for a while because I'd
> forgotten a basic Hobo tenet: /Always be aware of context/.
>
> I'd defined a tag that calls another custom tag as follows:
>
> <def tag="plans" attrs="showspecialcontrols">
> <my-table-plus:plans fields="plan_no,
> plan_type" showmycontrols="&showspecialcontrols">
> ...
> </def>
>
>
> But, for the longest time, the highlighted attribute call generated:
>
> undefined method `showspecialcontrols' for #<#<Class:...
>
> It took me a while to realize/remember that by including "plans" in my
> call to <my-table-plus:> I'd shifted the context for the attribute I'd
> passed in. Hobo was now looking for a /showspecialcontrols/ method on a
> plan, which didn't exist.
>
> Unless someone can contribute an alternate solution, I couldn't see a
> way around this without assigning the /showspecialcontrols/ attribute to
> an instance variable:
>
> <def tag="plans" attrs="showspecialcontrols">
>
> <!-- We need an instance variable here otherwise context is confused
> within call to my-table-plus -->
> <% @show = showspecialcontrols %>
>
> <my-table-plus:plans fields="..." showmycontrols="&@show">
>
>
> Tim
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Hobo Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to hobousers+...@googlegroups.com.
> To post to this group, send email to hobo...@googlegroups.com.
> Visit this group at http://groups.google.com/group/hobousers.
> For more options, visit https://groups.google.com/groups/opt_out.

--
Ignacio Huerta Arteche
http://www.ihuerta.net
Tel�fono: 0034 645 70 77 35
Email realizado con software libre

kevinpfromnm

unread,
Jan 13, 2014, 3:05:48 PM1/13/14
to hobo...@googlegroups.com
Have you tried using this_parent.showspecialcontrols?

Tim Griffin

unread,
Jan 13, 2014, 8:54:51 PM1/13/14
to hobo...@googlegroups.com
Hey Kevin:
Good idea, but that just produces:

undefined method `showspecialcontrols' for nil:NilClass

Hey Ignacio:
How odd that you can't reproduce it. I'm currently using Hobo 2.0.1 - is there anything in a later version that would have altered this behaviour? 

So, evidently when calling my-table-plus:plans there is no "parent" (which I guess makes sense).

Deeper in my own definition of my-table-plus, I pass an attribute on as a value to another custom tag with no problem (as do many other Hobo tags). This difference here, is that the call to <my-table> doesn't shift the context. 

<def tag="my-table-plus" attrs="sort-field, sort-direction, sort-columns, showspecialcontrols" >
  ...
    <my-table showspecialcontrols="&showspecialcontrols" ....>
      <field-heading-row:>

But, I'm curious why you can't replicate the behaviour....!

Tim



--
You received this message because you are subscribed to a topic in the Google Groups "Hobo Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/hobousers/aHVmZTwPKn4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to hobousers+...@googlegroups.com.

Tim Griffin

unread,
Jan 14, 2014, 2:47:05 PM1/14/14
to hobo...@googlegroups.com
Mystery solved. 

I found the culprit: my use of a "part" attribute on the div that contained the tag trying to reference the attribute of the enclosing tag. And, not having included this little detail in my original posting, that suggests why, Ignacio, you were not able to reproduce the same issue.

So, in my full example, I should have shown my use of the part attribute:

<def tag="plans" attrs="showspecialcontrols">
  <div part="special_plans"
  <my-table-plus:plans fields="plan_no, plan_type" showmycontrols="&showspecialcontrols">
     ...
  </div
</def>

Including the "part" attribute shifted the context for my subsequent tag my-table-plus. 

Since I've just hit this very same problem with another example, I would really love to know why the "part" attribute shifts context. And, how is specifying "part" any different than simply tagging the <div> with an ID and using the updates="#div1,#div2" syntax. Is "part" now an antiquated way of doing things? 

Tim


Bryan Larsen

unread,
Jan 14, 2014, 2:56:40 PM1/14/14
to Hobo Users
A part necessarily has to be an independent context: Hobo needs to be able to render the part in isolation -- after all, when you update it, that's all it's rendering.

So I don't think it's your context that's shifted, it's just that you lost your local variables.   You have to explicitly tell Hobo about local variables:  http://hobocentral.net/manual/ajax#local-variables

Bryan



You received this message because you are subscribed to the Google Groups "Hobo Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hobousers+...@googlegroups.com.

Tim Griffin

unread,
Jan 14, 2014, 3:27:55 PM1/14/14
to hobo...@googlegroups.com
Ah, thanks for the clarification, Bryan. Time for me to re-read the manual, apparently!

With the agility example from the manual, is there really any difference to Hobo between this (the original):

<aside:>
  <h2>Project Members</h2>
  <collection:members part="members"/>
  <form:memberships.new update="members" reset-form refocus-form>
    <div>
      Add a member:
      <name-one:user/>
    </div>
  </form>
</aside:>

and this (other than being slightly more typing)? 

<aside:>
  <h2>Project Members</h2>
  <div id="div-members">
     <collection:members"/>
  </div>

  <form:memberships.new update="#div-members" reset-form refocus-form>
    <div>
      Add a member:
      <name-one:user/>
    </div>
  </form>
</aside:>


Tim

Ignacio Huerta

unread,
Jan 15, 2014, 12:45:00 PM1/15/14
to hobo...@googlegroups.com
Hi Tim,

I think that in your example there a couple of issues:

<div part="div-members">
<collection:members"/>
</div>

Instead of:

<div id="div-members">
<collection:members"/>
</div>



And one of these:

update="members"
updates="#members"

Instead of:

update="#members"

Apart from that, I think they would exactly the same thing.

Regards,
Ignacio

El 14/01/14 21:27, Tim Griffin escribió:
> I would really love to know *why the "part" attribute shifts
> context*. And, how is specifying "part" any different than
> simply tagging the <div> with an ID and using the
> updates="#div1,#div2" syntax. *Is "part" now an antiquated way
> of doing things?*
> /Always be aware of context/.
>
> I'd defined a tag that calls another custom tag as
> follows:
>
> <def tag="plans" attrs="showspecialcontrols">
> <my-table-plus:plans fields="plan_no,
> plan_type" showmycontrols="&__showspecialcontrols">
> ...
> </def>
>
>
> But, for the longest time, the highlighted attribute
> call generated:
>
> undefined method `showspecialcontrols' for #<#<Class:...
>
> It took me a while to realize/remember that by
> including "plans" in my call to <my-table-plus:> I'd
> shifted the context for the attribute I'd passed in.
> Hobo was now looking for a
> /showspecialcontrols/ method on a plan, which didn't
> exist.
>
> Unless someone can contribute an alternate solution,
> I couldn't see a way around this without assigning
> the /showspecialcontrols/ attribute to an instance
> variable:
>
> <def tag="plans" attrs="showspecialcontrols">
>
> <!-- We need an instance variable here otherwise
> context is confused within call to my-table-plus -->
> <% @show = showspecialcontrols %>
>
> <my-table-plus:plans
> fields="..." showmycontrols="&__@show">
>
>
> Tim
>
>
>
>
>
> --
> You received this message because you are subscribed to
> a topic in the Google Groups "Hobo Users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/hobousers/aHVmZTwPKn4/unsubscribe.
> To unsubscribe from this group and all its topics, send
> an email to hobousers+...@googlegroups.com
> <mailto:hobousers%2Bunsu...@googlegroups.com>.
> To post to this group, send email to
> hobo...@googlegroups.com
> <mailto:hobo...@googlegroups.com>.
> Visit this group at
> http://groups.google.com/group/hobousers.
> For more options, visit
> https://groups.google.com/groups/opt_out.
>
>
>
> --
> You received this message because you are subscribed to the
> Google Groups "Hobo Users" group.
> To unsubscribe from this group and stop receiving emails from
> it, send an email to hobousers+...@googlegroups.com
> <mailto:hobousers%2Bunsu...@googlegroups.com>.
>
> To post to this group, send email to hobo...@googlegroups.com
> <mailto:hobo...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/hobousers.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
> --
> You received this message because you are subscribed to a topic in
> the Google Groups "Hobo Users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/hobousers/aHVmZTwPKn4/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> hobousers+...@googlegroups.com
> <mailto:hobousers%2Bunsu...@googlegroups.com>.
> To post to this group, send email to hobo...@googlegroups.com
> <mailto:hobo...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/hobousers.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Hobo Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to hobousers+...@googlegroups.com.
> To post to this group, send email to hobo...@googlegroups.com.
> Visit this group at http://groups.google.com/group/hobousers.
> For more options, visit https://groups.google.com/groups/opt_out.

--
Ignacio Huerta Arteche
http://www.ihuerta.net
Teléfono: 0034 645 70 77 35
Reply all
Reply to author
Forward
0 new messages