I would have felt bad if I posted to the list for a typo but that
didn’t seem to be the issue.
It’s something related to declaring a constant. When I switchd
DAY_NAMES to day_names the code worked. What up with dat ?
I’d only tried running it through ERb with the typo fixed, which
worked – but experimenting a little more, it does indeed seem to be
true that when ActionPack does its rendering, constant assignments are
regarded as dynamic, which isn’t allowed. (“def x; A=1; end” won’t
even parse.) So this is a case where there’s a difference between
command-line erb and the erb that’s taking place programmatically in
the course of rendering.
You can, if you really want to, get around this with const_set, but
there’s probably no occasion where you’d really have a good reason to
define a constant in a view template.
I would have felt bad if I posted to the list for a typo but that
didn’t seem to be the issue.
It’s something related to declaring a constant. When I switchd
DAY_NAMES to day_names the code worked. What up with dat ?
Right, the whole example was basically to show what not to do of
course more eloquently demonstrated with purpose.
Thank you for checking and the explanation!
And I changed it to use a local variable thanks to this thread.
Right, the whole example was basically to show what not to do of
course more eloquently demonstrated with purpose.
Thank you for checking and the explanation!
Stuart
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.