John Wong
2006-Jun-13 08:09 UTC
[Rails] Custom Primary Key, Using Primary Key in Form "gives before_type_cast" error?
Hi guys, I''ve got a problem here which i need help from the pro''s in this mailing list I have a legacy app where the User table has a custom structure where "User_id" (username) is the primary key as well as the username used to log in User.rb (model) class User < ActiveRecord::Base set_table_name "cmf901" set_primary_key "user_id" end Login Controller class LoginController < ApplicationController def login @user = User.new end end When creating a Login form (login.rhtml) <%= start_form_tag :action => "process" %> <%= text_field ''user'', ''user_id'', :MAXLENGTH =>"10" %> <%= text_field ''user'', ''user_password'', :MAXLENGTH =>"20" %> <%= submit_tag "Login" %> <%= end_form_tag %> I get an error NoMethodError in Login#login Showing app/views/login/login.rhtml where line #11 raised: undefined method `user_id_before_type_cast'' for #<User:0x3cb61e8> Extracted source (around line #11): 8: </tr> 9: <tr> 10: <td>Username</td> 11: <td><%= text_field ''user'', ''user_id'', :MAXLENGTH =>"10" %></td> 12: </tr> 13: <tr> 14: <td>Password</td> All i want to do is use the standard rails way to create a login form(used in Scaffold to create new/update) and do some authentication
Mark Reginald James
2006-Jun-14 06:03 UTC
[Rails] Re: Custom Primary Key, Using Primary Key in Form "gives before_type_cast" error?
John Wong wrote:> I have a legacy app where the User table has a custom structure where > "User_id" (username) is the primary key as well as the username used > to log in > .... > undefined method `user_id_before_type_cast'' for #<User:0x3cb61e8> > 11: <td><%= text_field ''user'', ''user_id'', :MAXLENGTH =>"10" %></td><%= text_field ''user'', ''id'', :maxlength => 10 %> should work, but you should probably be using a non-AR form helper instead: <%= text_field_tag ''user_id'', params[:user_id], :maxlength => 10 %> @user = User.find_by_id(params[:user_id]) -- We develop, watch us RoR, in numbers too big to ignore.
John Wong
2006-Jun-15 06:51 UTC
[Rails] Re: Custom Primary Key, Using Primary Key in Form "gives before_type_cast" error?
Thx! Think that helped a lot.. I guess i''ll not use an AR form helper.. too bad the nice form highlighting and error messages will have to go as well :( On 6/14/06, Mark Reginald James <mrj@bigpond.net.au> wrote:> John Wong wrote: > > > I have a legacy app where the User table has a custom structure where > > "User_id" (username) is the primary key as well as the username used > > to log in > > .... > > undefined method `user_id_before_type_cast'' for #<User:0x3cb61e8> > > 11: <td><%= text_field ''user'', ''user_id'', :MAXLENGTH =>"10" %></td> > > <%= text_field ''user'', ''id'', :maxlength => 10 %> should work, but > you should probably be using a non-AR form helper instead: > > <%= text_field_tag ''user_id'', params[:user_id], :maxlength => 10 %> > > @user = User.find_by_id(params[:user_id]) > > > -- > We develop, watch us RoR, in numbers too big to ignore. > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >