I’m seeing some interesting behavior (so to speak) with global tags
(please correct me if that’s the wrong term). If I have the following
in app/behaviors/hello_behavior.rb:
class Behavior::Base
define_tags do
tag “hello” do |tag|
“Hello World!”
end
end
end
I would expect to be able to write <r:hello/> in any page to render
the text “Hello World!”.
This seems to work fine on pages that do not have a behavior
specified (i.e., the “Behavior” drop down is left at “”).
However, if I select the Archive behavior, instead of “Hello World!”
I get:
<div><strong>undefined tag `hello'</strong></div>
Any thoughts? If it’s a bug I’m happy to look into the cause. I just
thought I’d ask on the list before I started spelunking.
You may have found a bug that happened to me too! I used <r:parent>
tags
(from somebody’s plugin) on some of my pages (that had the Commentable
behavior), and now they are broken, but somehow the code_behavior plugin
isn’t. Maybe there’s a subtle difference in the code that I’m missing?
It always happens if I assign a behavior to the page that has a
“define_tags” section, while behaviors wthout specific tags leave my
global tags untouched.
So I guess what happens is that the behavior class overwrites the tags
defined in the Behavior::Base extension instead of adding their tags to
it.
I think that if you move your global tags definition into the
PageContext.rbyou wont have that problem, if these are realy global
tags I think this is
where you want them.
Or create a plugin that extends PageContext.
Dror
I tried reopening PageContext and adding my define_tags in a plugin, but
Rails didn’t seem to like that and refused to start. I required
page_context.rb to load the model class during plugin initialization and
extend it properly, but that approach didn’t work.
thanks, but that’s exactly what I’m doing right now - I just thought
extending PageContext might be the more elegant solution than prefixing
my plugin directories… Anyway - I’ll go with what works.
Yeah, I don’t know that it will get you anything, though. At issue is the
order in which the tags are loaded/defined, i.e. if a behavior is defined
before your global tags, those global tags won’t work on pages that have
the
behavior.
But if you can define them on PageContext they will be available on
every page.
Wolfgang, are you overriding PageContext#intialize and then calling #define_tag ?
It might be worth if it works in production and not in development, I
had a
similar problem with the PageContext and with a tagging plugin I did. My
solution was to put the code in PageContext.rb - test it in development
and
then move it to the plugin and test again in production.
I know this is a ugly solution, but I fifn’t find any other,
Yeah, I don’t know that it will get you anything, though. At issue is
the
order in which the tags are loaded/defined, i.e. if a behavior is
defined
before your global tags, those global tags won’t work on pages that have
the
behavior.
Unfortunately, that didn’t work, too. But since I can’t test it locally
at the moment and hence provide no details, I’ll go with the other
solution for the moment and post again when I can tell you more.
Wolfgang
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.