Restful_authentication: Why are columns I add to user table never populated?

Hi,

I’m using the restful_authentication plugin that I downloaded from
here – http://agilewebdevelopment.com/plugins/. I wanted to use the
plugin with an existing table I have, which has a column named
“user_type_id”. However, when I submit the form, although the columns
the plugin is expecting get populated, none of the ones I have
supplied do. Here is my form:

<%= start_form_tag(:action => “userconfirm”) %>

<%= hidden_field ‘user’, ‘user_type_id’, :value=>2 %>

First name
<%= text_field 'user', 'ship_to_first_name' %>

...

Username
<%= text_field 'user', 'login' %>

Password
<%= password_field 'user', 'password' %>

Confirm Password
<%= password_field 'user', 'password_confirmation' %>

<%= submit_tag "Create" %> <% end_form_tag %>

and here is the section defined in the controller.

    def userconfirm
            @user = User.new(params[:user])
            if @user.save
                    flash[:notice] = 'User was successfully

created.’
redirect_to :action => ‘list’
else
render :action => ‘userinfo’
end
end

The error I get is
ActiveRecord::StatementInvalid in RegisterController#userconfirm

Mysql::Error: #23000Column ‘user_type_id’ cannot be null: INSERT INTO
users (created_on, last_login, pharmacy_id, provincial_tax,
salt, tax, work_phone, work_phone_extension, cc_company,
cc_number, discount, ship_to_city, ship_to_last_name,
user_type_id, cc_security_code, comments, company_name,
crypted_password, bill_to_attn, bill_to_country,
bill_to_street2, demo, ship_to_country, updated_on,
activation_code, dateofbirth, html_email_pref,
lock_order_form_prices, ship_to_street, ship_to_zip,
show_retail_prices, user_group_id, bill_to_city, enabled,
bill_to_company, user_agent, fax, phone, ship_to_attn,
ship_to_street2, shipping, bill_to_last_name, bill_to_street,
cc_exp_date, reseller_id, user_id, bill_to_state, login,
ship_to_first_name, ship_to_state, bill_to_first_name,
bill_to_zip, email, po_num, ship_to_company)
VALUES(‘2008-01-22 09:03:30’, NULL, NULL,
0.0, ‘deb98c56f0a3f750c9d66869903ef573be1774f5’, 0.0, NULL, NULL,
NULL, NULL, 0.0, NULL, NULL, NULL, NULL, NULL, ‘’,
‘5e9f6eb74cbb331641afe002ecce8f5f612d358b’, NULL, NULL, NULL, 0, NULL,
‘2008-01-22 09:03:30’, ‘399806887d510ca24311133ca86775d9946f3644’,
NULL, 1, 0, NULL, NULL, 1, NULL, NULL, 1, NULL, NULL, NULL, NULL,
NULL, NULL,
0.0, NULL, NULL, NULL, NULL, NULL, NULL, ‘laredo223’, NULL, NULL,
NULL, NULL, ‘[email protected]’, NULL, NULL)

RAILS_ROOT: ./script/…/config/…
Application Trace | Framework Trace | Full Trace

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/connection_adapters/abstract_adapter.rb:128:in log' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/ active_record/connection_adapters/mysql_adapter.rb:243:in execute’

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/connection_adapters/mysql_adapter.rb:253:in insert' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/ active_record/base.rb:1814:in create_without_callbacks’

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/callbacks.rb:254:in create_without_timestamps' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/ active_record/timestamp.rb:30:in create’

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/base.rb:1792:in create_or_update_without_callbacks' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/ active_record/callbacks.rb:242:in create_or_update’

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/base.rb:1548:in save_without_validation' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/ active_record/validations.rb:752:in save_without_transactions’

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/transactions.rb:129:in save' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/ active_record/connection_adapters/abstract/database_statements.rb: 59:in transaction’

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/transactions.rb:95:in transaction' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/ active_record/transactions.rb:121:in transaction’

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/transactions.rb:129:in save' /usr/local/apache2/htdocs/easyrx/app/controllers/ register_controller.rb:59:in userconfirm’

Hi,

Did you add your custom column to the list of columns listed after

attr_accessible?

attr_accessible :user_type_id, :email, :login, :password,
:password_confirmation

something like that

Binh

is :user_type_id set in attr_protected?

On Jan 23, 2008 3:21 AM, [email protected] <
[email protected]> wrote:

<%= start_form_tag(:action => “userconfirm”) %>
<%= password_field ‘user’, ‘password’ %>


if @user.save
ActiveRecord::StatementInvalid in RegisterController#userconfirm
show_retail_prices, user_group_id, bill_to_city, enabled,
NULL, 1, 0, NULL, NULL, 1, NULL, NULL, 1, NULL, NULL, NULL, NULL,
active_record/connection_adapters/mysql_adapter.rb:243:in `execute’

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/transactions.rb:129:in save' /usr/local/apache2/htdocs/easyrx/app/controllers/ register_controller.rb:59:in userconfirm’


Ryan B.

Feel free to add me to MSN and/or GTalk as this email.

Yup that was it. I added it to attr_accessible and the user was
created. Thanks for the help. 5 stars. - Dave