Update Local Variables?


#1

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


#2

On May 19, 6:59 pm, Tyler K. 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