# Update Local Variables?

**URL:** <https://www.ruby-forum.com/t/update-local-variables/168344>\
**Category:** Rails\
**Created:** [May 19, 2009, 7:59pm UTC](https://www.ruby-forum.com/t/update-local-variables/168344 "2009-05-19T19:59:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![knappe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/5fc32e/32.png) [@knappe](https://www.ruby-forum.com/u/knappe)\
**Post date:** [May 19, 2009, 7:59pm UTC](https://www.ruby-forum.com/t/update-local-variables/168344/1 "2009-05-19T19:59:30Z")

</div>

I’m having a problem updating local variables. I was using some  
date.select and time.select forms to save content to my database.

```
            <%# f.label :StartTime %>
            <%# f.time_select :start_time %>
            <br />
            <%# f.label :EndTime %>
            <%# f.time_select :end_time %>

```

However, I would rather use calendardateselect  
([Google Code Archive - Long-term storage for Google Code Project Hosting.](http://code.google.com/p/calendardateselect/)). I can access the value  
returned from the user click on the calendar by this:

```
   <%= calendar_date_select_tag "calendar",
            Date.today,
            :embedded => true,
            :year_range => 1.years.ago..0.years.ago,
            :time => true,
            # this correctly calls the alert
            #:onchange => "alert( 'End = ' + $F(this ));"
            :onchange => end_date_time = $F

    %>

```

Using an :onchange to update the value of end\_date\_time. However, I  
want to then do some string slicing on end\_date\_time to separate out the  
date and times. I have tried to do this as part of the :onchange  
action, but I have nil values:

:onchange =\> start\_date\_time = $F, end\_date = end\_date\_time[1,4]}

My question is two fold; I want to update the local values for time and  
date. Is this the best method? How would I go about doing it? Google  
seems to be failing me, but I’m new to RoR so I may be searching for the  
wrong thing.

---

<div class="post-metadata">

**Author:** ![knappe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/5fc32e/32.png) [@knappe](https://www.ruby-forum.com/u/knappe)\
**Post date:** [May 19, 2009, 10:34pm UTC](https://www.ruby-forum.com/t/update-local-variables/168344/2 "2009-05-19T22:34:19Z")

</div>

On May 19, 6:59 pm, Tyler K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> :onchange =\> start\_date\_time = $F, end\_date = end\_date\_time[1,4]}
> 
> My question is two fold; I want to update the local values for time and  
> date. Is this the best method? How would I go about doing it? Google  
> seems to be failing me, but I’m new to RoR so I may be searching for the  
> wrong thing.

You seem to have a misapprehension about what code is being run  
where: :onchange is a javascript fragment - you need to write a chunk  
of javascript to do this. that chunk of javascript cannot do anything  
to any ruby variables (other than by causing a request to be made).  
The reason you get the error that you get is that ruby evaluates  
start\_date\_time = $F, end\_date = end\_date\_time[1,4] at the point that  
your template is rendered and you presumably don’t use a global  
variable called $F.

I’ve never used calendardateselect and I’m not entirely sure what  
you’re trying to do, but either you need to do some client side stuff  
or you need something in your action to preprocess what gets  
submitted.

Fred
