# AWDWR question

**URL:** <https://www.ruby-forum.com/t/awdwr-question/98563>\
**Category:** Rails\
**Created:** [July 16, 2006, 2:46am UTC](https://www.ruby-forum.com/t/awdwr-question/98563 "2006-07-16T02:46:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [July 16, 2006, 2:46am UTC](https://www.ruby-forum.com/t/awdwr-question/98563/1 "2006-07-16T02:46:33Z")

</div>

In an early section on Action View, showing code being put directly  
into the rhtml file:

\<% require ‘date’  
DAY\_NAMES = %w{ Sunday Monday Tuesday Wednesday Thursday Friday Saturday  
}  
today = Date.today %\>

# Hello, Dave

It's \<%= DAY\_NAMES[today.wday] %\>. Tomorrow is \<%= DAY\_NAMES[(today + 1).wday %\>.

I get this error -

compile error  
./script/…/config/…/app/views/signup/registration.rhtml:2: dynamic  
constant assignment  
DAY\_NAMES = %w{ Sunday Monday Tuesday Wednesday Thursday Friday Saturday  
}  
^  
./script/…/config/…/app/views/signup/registration.rhtml:8: parse  
error, unexpected ‘)’, expecting ‘]’  
\_erbout.concat "Tomorrow is "; \_erbout.concat(( DAY\_NAMES[(today +  
1).wday ).to\_s); \_erbout.concat “.\n”

Something wrong with declaring the constant ?

Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [July 16, 2006, 3:01am UTC](https://www.ruby-forum.com/t/awdwr-question/98563/2 "2006-07-16T03:01:51Z")

</div>

Hi –

On Sat, 15 Jul 2006, Dark A. wrote:

> Tomorrow is \<%= DAY\_NAMES[(today + 1).wday %\>.  
> You’re missing a ] on that last line, after wday.

David

–  
[http://www.rubypowerandlight.com](http://www.rubypowerandlight.com) =\> Ruby/Rails training & consultancy  
[Ruby for Rails](http://www.manning.com/black) =\> RUBY FOR RAILS (reviewed on  
Slashdot, 7/12/2006!)  
[http://dablog.rubypal.com](http://dablog.rubypal.com) =\> D[avid]A[.]B[lack’s][Web]log  
removed\_email\_address@domain.invalid =\> me

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [July 16, 2006, 3:39am UTC](https://www.ruby-forum.com/t/awdwr-question/98563/3 "2006-07-16T03:39:17Z")

</div>

Hi –

On Sat, 15 Jul 2006, Dark A. wrote:

> > }  
> > David
> 
> 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.

David

–  
[http://www.rubypowerandlight.com](http://www.rubypowerandlight.com) =\> Ruby/Rails training & consultancy  
[Ruby for Rails](http://www.manning.com/black) =\> RUBY FOR RAILS (reviewed on  
Slashdot, 7/12/2006!)  
[http://dablog.rubypal.com](http://dablog.rubypal.com) =\> D[avid]A[.]B[lack’s][Web]log  
removed\_email\_address@domain.invalid =\> me

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [July 16, 2006, 3:11am UTC](https://www.ruby-forum.com/t/awdwr-question/98563/4 "2006-07-16T03:11:30Z")

</div>

On 7/15/06, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > # Hello, Dave
> > 
> > It's \<%= DAY\_NAMES[today.wday] %\>. Tomorrow is \<%= DAY\_NAMES[(today + 1).wday %\>.
> 
> You’re missing a ] on that last line, after wday.
> 
> David

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 ?

Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [July 16, 2006, 6:00am UTC](https://www.ruby-forum.com/t/awdwr-question/98563/5 "2006-07-16T06:00:55Z")

</div>

On Jul 15, 2006, at 8:43 PM, Dark A. wrote:

> 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.

Dave

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [July 16, 2006, 3:45am UTC](https://www.ruby-forum.com/t/awdwr-question/98563/6 "2006-07-16T03:45:26Z")

</div>

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
