It wasn’t even 4-5 hours after I could resolve a problem regarding
error_messages_for, I ran into a new issue.
I have a table whose primary key is set to email address and there is
not need for an auto incremented number in the table. I’ve updated the
model, with the info, as follows:
set_primary_key 'email_address'
Now, I have a registration form, which will post all the needed info
to the controller, along with the email address.
In the controller, I’m creating a new record:
@user = User.create ( :email_address =>
params[:email_address], :name => params[:name])
@user.password = ‘xyz’
if !@user.save
puts “An error occured, while trying to create an account for
#{params[:email_address]}”
end
The create method call never succeeds, as it is passing nil to email,
even if params[:email_address] contains the actual value (I’ve
verified this by the printing it!) passed.
If I remove the set_primary_key in the model definition and try the
action again, a record gets created with email and name properly set,
however, after setting password (which also succeeds) and then trying
to save I get an error.
The log shows something like:
There is no field id in the table: UPDATE users SET email_address =
‘[email protected]’, name = ‘ABCD’, password = ‘xyz’ where id = 0
I wonder where this id = 0 is coming from? None of the two methods
work for me. Am I missing anything here? Your help would be very
invaluable. Thank you a ton in advance.