Hi David,
>I've got some ESI variables in a template, and am trying to assign
>their values to Ruby variables. Strangely, it seems to work and not
>work at the same time.
Why mixing them anyway?
> <esi:vars>
> <% state = "$(GEO{'region_code'})" %>
> <% city = "$(GEO{'city'})" %>
>
> State: <%= state %><br/> # CT
> City: <%= city %><br/> # NEWHAVEN
<% # becomes: %>
State: $(GEO{'region_code'})
City: $(GEO{'city'})
<% # so the ESI processor replaces them after ERB %>
> Massaged city: <%= CITIES[state][city] %> # Uses the literal EIS strings
<% # becomes: %>
Massaged city: <%= CITIES["$(GEO{'region_code'})"]["$(GEO{'city'})"]
# => "KEYING LITERAL ESI STRINGS" %>
<% # so the ESI processor replaces ... nothing. %>
> </esi:vars>
>So, strange as it sounds, the variables seem to be differently bound
>depending on which line is being evaluated. So far I've not been able
>to puzzle through the sequence of events in such a way as to come up
>with a way to inject the state and city values into a call to the
>CITIES hash. I'd be interested in any ideas or solutions people might
>have.
You can:
process the template with the ESI proc before it's evaluated by erb
or drop erb and define your mapping as ESI variables by writing a script that
writes the complete mapping into an esi:include'd file
or drop ESI and expose the GEO server variables to erb...
or define
class ESIlabeth < Struct.new(:name, :words)
def initialize(name, *words)
super name, words.flatten
end
def [](word)
self.class.new name, words + [ word ]
end
def to_s
ugh = words.map { |word| "[#{ word.inspect }]" }.join
%Q'<% #{ name }#{ ugh } %>'
end
# or implement to_s in a way it resolves the http vars and then
# accesses the real CITIES storage.
end
CITIES = ESIlabeth.new 'CITIES'
# puts CITIES["$(GEO{'region_code'})"]["$(GEO{'city'})"]
# => CITIES["$(GEO{'region_code'})"]["$(GEO{'city'})"]
and parse it again after ESI did its stuff... :)
or implement your own ESI processor and embed it into ruby, ...
It's a matter of the problems environment. Hope I could help.
best
Florian
--
Florian Aßmann
Fork Unstable Media
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.