I'm using the latest version of RoR installed on Fedora Core 6 Linux
with Apache 2.2. I just installed the plugin
"restful_authentication" (http://agilewebdevelopment.com/plugins/
restful_authentication), but whenever I try and create a new user, via
this code:
def userconfirm
@user = User.new(params[:user]) # line 59
if @user.save
flash[:notice] = 'User was successfully
created.'
redirect_to :action => 'list'
else
render :action => 'userinfo'
end
end
but I get this error. Where do I find this "crypted_password" method?
- Dave
NameError in RegisterController#userconfirm
undefined local variable or method `crypted_password' for #<User:
0xb766e3a8>
RAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace | Full Trace
after installing the plugin, then it should have generated a migration
which creates the users table with the necessary attributes.
If you didn't and your Users table already exists, you can generate
the rest of the stuff by using the --skip-migration option on the
generate.
You can see the fields which are needed in this case by looking in
vendor/plugins/restful_authentication/generators/authenticated/templates/migration.rb
Ok, I added the column "crypted_password" to my users table. I assume
this means I should have deleted the column "password". Anyway, now I
get another warning when I try and create a user. Upon completing the
fields and entering a password and a confirmed password, I get
There were problems with the following fields:
* Password confirmation can't be blank
even though I'm entering a value for password confirmation. I don't
have a field "password_confirmation" in my database ... didn't think I
needed one. This is what the code looks like:
How do I get salt defined? Here is the code in my user.rb file:
protected
# before filter
def encrypt_password
return if password.blank?
self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--
#{login}--") if new_record? # line 88
self.crypted_password = encrypt(password)
end
and here is code from my register_controller.rb file:
def userconfirm
@user = User.new(params[:user])
if @user.save # line 59
flash[:notice] = 'User was successfully
created.'
redirect_to :action => 'list'
else
render :action => 'userinfo'
end
end
Thanks for this. One problem I'm having right now is setting up a
form that logs the user in. I couldn't find any documentation on your
page. Here's my form right now:
The plugin is used as a generator which creates the models,
controllers, and the migration.
Used correctly, there's no need to add any fields, the generated
migration does it for you.
Ah,not quite.
The migration will create a table, yes, but it has the line
create_table "users", :force => true do |t|
Doesn't this zap any previous table?
In the ActiveRecord code I see the lines
if options[:force]
drop_table(table_name, options) rescue nil
end
Which means that any previous information that may have been in the
table such as 'address' is now lost. Id rather that didn't happen.
I've written here before about this problem with plugins and the
migrations they generate but no-one picked up on it.
This is particularly pernicious in the case of restful_authentication
when security is being added to an already partially developed
application. It really does need to be addressed.