Index => nil params jumbled *sometimes*


#1

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?


#2

did you check if it is rendered correctly? whats your html output for
that code?


#3

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…

J080183 - Dynamix Office 855 Grandview J080181 - CCC Westlake Phase 1 Building ... Bereavement Vacation ...

#4

as rendering the view seems ok, i suppose it has something to do with
the logic behind it.

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.

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?

#5
  • 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.


#6

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 :wink:

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

#7

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.


#8

Anyone else by chance? It really seems like this is a lower level
error…


#9

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”}]}


#10

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.


Rails Wheels - Find Plugins, List & Sell Plugins -
http://railswheels.com


#11

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


#12

Thanks for your help, it seems to have been having the hidden elements
outside a

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