Forum: Ruby on Rails index => nil params jumbled *sometimes*

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Matt D. (Guest)
on 2008-12-29 16:15
(Received via mailing list)
My app has a timesheet, which is a collection of many TimeCards, based
on a Date.
I have one user that can create new TimeCards just fine, except on
three associated Jobs. Each time he saves he gets a 500 error.

Looking at the params, they come across jumbled and my processing
method chokes:
(The first "time_cards" entry is correct, the second is split by the
third)

Parameters:
  {
    "date"=>"2008-12-17",
    "time_cards"=>[
      {
        "job_id"=>"3107",
        "time_card_entry_type"=>"Field",
        "time_card_date"=>"2008-12-17",
        "id"=>"285875",
        "note"=>"Akron e-rate cable project counts/ FSR
presentation",
        "hours"=>"2",
        "user_id"=>"178"
      },
      {
        "time_card_date"=>"2008-12-17",
        "id"=>"285774",
        "user_id"=>"178"
      },
      {
        "job_id"=>"3089",
        "time_card_entry_type"=>"Field",
        "time_card_date"=>"2008-12-17",
        "id"=>"",
        "note"=>"progress drawing and spec revision",
        "hours"=>"2.5",
        "user_id"=>"178"
      },
      {
        "job_id"=>"3107",
        "time_card_entry_type"=>"Field",
        "note"=>"Akron e-rate cable project counts",
        "hours"=>"2"
      }
    ]
  }


The form is a partial that uses index => nil, and it works for all
other users, except this guy, on these associated Jobs.

%tr.entry
  - fields_for "time_cards[]", entry, :index => nil do |entry_form|
    = entry_form.hidden_field(:time_card_date, :value => @date)
    = entry_form.hidden_field(:user_id, :value => session
[:timesheet_user].id)
    = entry_form.hidden_field(:id)

    %td= entry_form.select :job_id, available_jobs
    %td= entry_form.select :time_card_entry_type, allowable_types
    %td= entry_form.text_field :hours, :size => 5
    %td= entry_form.text_field :note


I've scratched my head on this one for weeks, anything look out of
order?
MaD (Guest)
on 2008-12-29 16:50
(Received via mailing list)
did you check if it is rendered correctly? whats your html output for
that code?
Matt D. (Guest)
on 2008-12-29 16:54
(Received via mailing list)
On Dec 29, 9:50 am, MaD <removed_email_address@domain.invalid> wrote:
> did you check if it is rendered correctly? whats your html output for
> that code?

Yep, it renders correctly (below); as noted, it works for all but one
user...

<tr class='entry'>
  <input id="time_cards__time_card_date" name="time_cards[]
[time_card_date]" type="hidden" value="2008-12-28" />
  <input id="time_cards__user_id" name="time_cards[][user_id]"
type="hidden" value="121" />
  <input id="time_cards__id" name="time_cards[][id]" type="hidden" />

  <td>
    <select id="time_cards__job_id" name="time_cards[]
[job_id]"><option value="3375">J080183 - Dynamix Office 855 Grandview</
option>
    <option value="3373">J080181 - CCC Westlake Phase 1 Building</
option>
    ...
  </td>

  <td>
    <select id="time_cards__time_card_entry_type" name="time_cards[]
[time_card_entry_type]"><option value="Bereavement">Bereavement</
option>
    <option value="Vacation">Vacation</option></select>
    ...
  </td>
  <td><input id="time_cards__hours" name="time_cards[][hours]"
size="5" type="text" /></td>
  <td><input id="time_cards__note" name="time_cards[][note]" size="30"
type="text" /></td>
</tr>
MaD (Guest)
on 2008-12-29 17:08
(Received via mailing list)
as rendering the view seems ok, i suppose it has something to do with
the logic behind it.

<stating the obvious>
so far your posted params show, that your controller receives the
second entry as first parameter, the first entry gets split by the
third, which is not yet saved or the id got lost. additionally: all
this only happens for one user.
</stating the obvious>

honestly: this seems strange. some points to start looking for an
answer:
- are you able to reproduce the error, if you login as that user?
- what about that user? does he have any 'special qualities' (like:
has special rights or uses lynx to access the site *g*)?
- does your session variable contain the correct data?
Matt D. (Guest)
on 2008-12-29 17:33
(Received via mailing list)
> honestly: this seems strange. some points to start looking for an
> answer:
> - are you able to reproduce the error, if you login as that user?
> - what about that user? does he have any 'special qualities' (like:
> has special rights or uses lynx to access the site *g*)?
> - does your session variable contain the correct data?

It sure does ;)

- If I login as the user, I can't seem to reproduce the error, but
this happens constantly for this one guy, on these three Jobs. Ugh.
- The user is just a standard User, no awesome Admin qualities, and he
uses IE7 against my better judgment
- The session[:timesheet_user].id is correct (and correctly set in the
params hash)
- A TimeCard with a blank ID means that it is new (and not yet saved).
MaD (Guest)
on 2008-12-29 17:42
(Received via mailing list)
> - If I login as the user, I can't seem to reproduce the error, but
> this happens constantly for this one guy, on these three Jobs. Ugh.

this sucks. but i think as long as you can't reproduce the error, you
porbably won't be able to fix it.
Matt D. (Guest)
on 2008-12-29 17:58
(Received via mailing list)
On Dec 29, 10:41 am, MaD <removed_email_address@domain.invalid> wrote:
> > - If I login as the user, I can't seem to reproduce the error, but
> > this happens constantly for this one guy, on these three Jobs. Ugh.
>
> this sucks. but i think as long as you can't reproduce the error, you
> porbably won't be able to fix it.

I can't reproduce it, but I can see the effect. Everything seems to be
in place and the snag is that the params is jumbled. I'm not doing
anything against Rails' opinion ;(

hrm.
Matt D. (Guest)
on 2008-12-29 20:47
(Received via mailing list)
Anyone else by chance? It really seems like this is a lower level
error...
Mark Reginald J. (Guest)
on 2008-12-30 01:17
(Received via mailing list)
Matt D. wrote:

> <tr class='entry'>
>   <input id="time_cards__time_card_date" name="time_cards[]
> [time_card_date]" type="hidden" value="2008-12-28" />
>   <input id="time_cards__user_id" name="time_cards[][user_id]"
> type="hidden" value="121" />
>   <input id="time_cards__id" name="time_cards[][id]" type="hidden" />
>
>   <td>

Those first three fields are not enclosed in a cell.
That may cause IE to send the parameters in the wrong order.

Please log and post the raw_post string.

--
Rails Wheels - Find Plugins, List & Sell Plugins -
http://railswheels.com
Matt D. (Guest)
on 2008-12-30 04:14
(Received via mailing list)
> Those first three fields are not enclosed in a cell.
> That may cause IE to send the parameters in the wrong order.
>
> Please log and post the raw_post string.

Ahh, IE, my old friend. Perhaps this is why I wasn't able to recreate
it.

Here is the raw POST:

Processing TimeCardsController#day (for 192.168.1.192 at 2008-12-18
09:14:13) [POST]
Parameters: {"date"=>"2008-12-17", "time_cards"=>[{"job_id"=>"3107",
"time_card_entry_type"=>"Field", "time_card_date"=>"2008-12-17",
"id"=>"285875", "note"=>"Akron e-rate cable project counts/ FSR
presentation", "hours"=>"2", "user_id"=>"178"},
{"time_card_date"=>"2008-12-17", "id"=>"285774", "user_id"=>"178"},
{"job_id"=>"3089", "time_card_entry_type"=>"Field",
"time_card_date"=>"2008-12-17", "id"=>"", "note"=>"progress drawing
and spec revision", "hours"=>"2.5", "user_id"=>"178"},
{"job_id"=>"3107", "time_card_entry_type"=>"Field", "note"=>"Akron e-
rate cable project counts", "hours"=>"2"}]}
Mark Reginald J. (Guest)
on 2008-12-30 12:42
(Received via mailing list)
Matt D. wrote:
>> Those first three fields are not enclosed in a cell.
>> That may cause IE to send the parameters in the wrong order.
>>
>> Please log and post the raw_post string.
>
> Ahh, IE, my old friend. Perhaps this is why I wasn't able to recreate
> it.

Well, I can't blame IE for tripping up on invalid HTML.

> Here is the raw POST:
>
> Processing TimeCardsController#day (for 192.168.1.192 at 2008-12-18
> 09:14:13) [POST]
> Parameters: {"date"=>"2008-12-17", "time_cards"=>[{"job_id"=>"3107",
> "time_card_entry_type"=>"Field", "time_card_date"=>"2008-12-17",

What you really need to look at is not the params hash,
but the string posted by the browser. See this by adding
"logger.info request.raw_post" to your controller action.

If the parameters are indeed posted out of order, then the
problem was with the missing td tags. However a correct
order would instead suggest a bug in Rails' parameter processing.

--
Rails Wheels - Find Plugins, List & Sell Plugins -
http://railswheels.com
Matt D. (Guest)
on 2008-12-30 16:00
(Received via mailing list)
Thanks for your help, it seems to have been having the hidden elements
outside a <td>.
I wouldn't think that having hidden elements outside a cell (but still
in the form) would be invalid, but then again, I didn't explicitly
validate.

Thanks for your help ;)
This topic is locked and can not be replied to.