[Rails-core] RFC: Safely accessing the params hash

Michael Koziarski
2005-08-08T13:46:52Z

> As this is not the case (yet), I have to handle this case manually in
> controllers:
>
>   employee.task_ids = params[:employee][:task_ids]



> On a sunny day it''ll even work. As params[:employee] can be nil,
there''s
> a lurking failure. As a solution, I propose to implement params
> explicitly like this (B)

I don''t know that I like this,  seems like a recipie for confusing,
hard to track down bugs?

It may become difficult to ''eyeball'' the code params[:blah]
looks like
params(:blah), but behaves differently.  Isn''t two lines of code
better here:

ids = params[:employee][:task_ids] rescue nil
do_such_and_such(ids) if ids

I''m all for clever code,  but perhaps making things explicit is better
in this case.
--
Cheers

Koz