hi, i''m very new to RoR,
i''m following an example on the book (Agile Web Development with Rails
2nd ed.)
i met an error that goes like this (even though i followed the book word
for word)
>>
ArgumentError in Login#add_user
Showing app/views/login/add_user.rhtml where line #16 raised:
wrong number of arguments (0 for 1)
Extracted source (around line #16):
13:
14: <p>
15: <label for="user_password">Password:</label>
16: <%= form.password_field :password, :size => 40 %>
17: </p>
18:
19: <p>
here are my .rb and .rhtml
add_user.rhtml:
<div class="depot-form">
<%= error_messages_for ''user'' %>
<fieldset>
<legend>Enter User Details</legend>
<% form_for :user do |form| %>
<p>
<label for="user_name">Name:</label>
<%= form.text_field :name, :size => 40 %>
</p>
<p>
<label for="user_password">Password:</label>
<%= form.password_field :password, :size => 40 %>
</p>
<p>
<label
for="user_password_confirmation">Confirm:</label>
<%= form.password_field :password_confirmation, :size => 40 %>
</p>
<%= submit_tag "Add User", :class => "submit"
%>
<% end %>
</fieldset>
</div>
----------------------------------------------------------
login_controller.rb:
class LoginController < ApplicationController
layout "admin"
def add_user
@user = User.new(params[:user])
if request.post? and @user.save
flash.now[:notice] = "User #{@user.name} created"
@user = User.new
end
end
def login
end
def logout
end
def index
end
def delete_user
end
def list_user
end
end
------------------------------------------------------------------
user.rb:
require ''digest/sha1''
class User < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :name
attr_accessor :password_confirmation
validates_confirmation_of :password
def validate
errors.add_to_base("Missing password!!!" ) if
hashed_password.blank?
end
def self.authenticate(name, password)
user = self.find_by_name(name)
if user
expected_password = encrypted_password(password, user.salt)
if user.hashed_password != expected_password
user = nil
end
end
user
end
def password
@password
end
def password(pwd)
@password = pwd
create_new_salt
self.hashed_password = User.encrypted_password(self.password,
self.salt)
end
private
def self.encrypted_password(password, salt)
string_to_hash = password + "wibble" + salt
Digest::SHA1.hexdigest(string_to_hash)
end
def create_new_salt
self.salt = self.object_id.to_s + rand.to_s
end
end
------------------------------------------
Thanks alot in advance, i''m really lost here!
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---