views:

46

answers:

2

I am revising someone else's project which allows users to submit content either for either immediate or scheduled publication. There are a pair of radio buttons to select this, and a datetime field that is enabled by javascript if the radio button for 'scheduled' is selected

<%= f.hidden_field :scheduled_state %>
<%= f.radio_button :immediate_or_scheduled, :immediate, :checked => "checked", :id => "pub_imd" %>

<%= f.radio_button :immediate_or_scheduled, :scheduled , :id => "pub_sch" %>
        <label>Date/Time:</label>

        <%= f.datetime_select :scheduled_start,
                              {:include_blank => false,
                                :default => 3.days.from_now,
                                :start_year => Time.now.year} %>

I'm not totally clear what the hidden field is for, that is my next point of investigation. Anyway, the problem is that when the form is submitted, sometimes the parameters just aren't submitted. I would copy the mongrel output, but all you see is that there is no :scheduled_start(1i) => 2010. It doesn't say that it is nil, it just does not have that parameter.

The thing that really gets me is that it is not a consistent issue - I can submit three times in a row with a scheduled date correctly and then it will fail. I have not been able to correlate with specific dates - some seem to mess up more than others but none are really consistent.

My attempted fixes-

  • Originally :include_blank got true, and I thought maybe it wasn't sending properly. Was irrelevant.

  • Tried turning off the javascript that disabled/enabled the select field, but was irrelevent.

  • Tried hardcoding the form in with pure html, made no difference.

  • Tried putting in custom rails select_tags for my own parameters, then pick them up in the controller and add them to the parameters. Still didn't help, and broke the immediate publication option.

I'm pretty solidly stumped, if anyone has a new direction I can examine that would be great. Thanks!

A: 

without seeing the top of your form, i can't tell if you are using a form_for statement, but if not, you may add the object as the first argument

f.datetime_select 'post', 'scheduled_start', {options hash here}

api here http://apidock.com/rails/ActionView/Helpers/DateHelper/datetime_select

Jed Schneider
A: 

I am the original poster, but I cannot comment because I posted originally as an unregistered user. If some admin could make this a comment that would be great.

OK, I looked at the net pane and even when it fails, it still is sending the parameters from the form in the post request. I am using the form_for helper. I tried writing a section into the controller to capture the params and assign them to the object like so

@scheduled_start_hack = "#{params[:press_release][:"scheduled_start(2i)"]}.#{params[:press_release][:"scheduled_start(3i)"]}.#{params[:press_release][:"scheduled_start(1i)"]} - #{params[:press_release][:"scheduled_start(4i)"]}:#{params[:press_release][:"scheduled_start(5i)"]}#{@meridian}"

@press_release = PressRelease.new(params[:press_release])

@press_release.scheduled_start = @scheduled_start_hack

That snippet has a bunch of conditionals I didn't bother posting left out so that it did not do it in case things were undefined or it was not supposed to be a scheduled start or to format it correctly etc. I got it to puts out the @scheduled_start_hack correctly formatted, but it still rejected the @press_release.save because it said "Scheduled start can't be blank" like before.

I've definitely noticed that the error occurs mainly in production. It has been a long time since one failed to go through in local development, and a long time since one went through successfully on production.

Thanks for all your responses.

NealJMD