nil values being set in scaffold generated code for 1.2.3

Hi Andrew,

Andrew Don wrote:

@user = User.new(params[:user])
The above line should populate a user object with values entered by the
client. Unfortunately the user object is populated with nil values, even
though the params user object has the client entered values. This seems
very unusual and more than likely an error on my part, but suggestions
about resolving the problem would be welcome.

When you say the "user object is populated with nil values", do you mean the Rails object, or the related record in the database? If the latter, my first suggestion would be to check to see if there's a validation that's keeping the User.save from succeeding. If there's not an obvious (one you look) problem there, I'd suggest you post some additional code.

Best regards,
Bill

Hi Andrew,

Andrew Don wrote:

Thanks for responding.

You're welcome.

The code extract below is taken from the user
controller object and is scaffold generated code :
def create
@user = User.new(params[:user])
if @user.save
   flash[:notice] = 'User was successfully saved.'
etc etc.
I ran the code in debug mode setting a breakpoint just below the line
'@user = User.new(params[:user])' and found that values entered on the
browser were present in the params object but all the columns/attributes
of the user object were null.

Not sure what you're using to look at the user object, but when you say "all the columns" it makes me wonder if you're looking at the database rather than the in-memory object.

There are model validations against the object in user.rb
and these are correctly validated and return a list of
failures , as the values in @user are all null.

To test whether the values in @user are, in fact, null, comment out the save and make a new view (just rename the old one) to be rendered by this controller method. In it, just render the values of the @user attributes (e.g., <%= @user.name %>).

It would appear that there is a problem in the initialisation
of the @user object, but of course this assumption is surely
not correct.

Anything is possible, but I'd bet a nickle that the problem is in your validations. They can get tricky. For starters, comment out all your validations and see what gets saved. Then start adding the validations back to identify the one that's giving you problems.

Best regards,
Bill