Hey all,
I’m following the Authenticating Your Users Recipe in Rails recipes,
which is a bit outdated I know.
It says run a migration:
def self.up
create_table :users do |t|
t.column “username”, :string
t.column “password_salt”, :string
t.column “password_hash”, :string
end
end
And then create a form:
<% form_for @user, :url => { :action => “signup” } do |f| %>
<%= f.label(:username, “username”)%>
<%= f.text_field(:username) %>
<%= f.label(:password, “password”)%>
<%= f.password_field(:password) %>
<%= f.submit(“Sign Up”)%>
<% end %>
#Note that he’s using the now defunct start_from_tag
Problem is because I don’t have a password field in users table in
database, I think it gives undefined method error for password when I
pass as argument in the password_field() method. However, in the book,
he does exactly that and it works for him.
Is there anything I’m doing wrong?
Thanks for response.
John M. wrote in post #968183:
Hey all,
I’m following the Authenticating Your Users Recipe in Rails recipes,
which is a bit outdated I know.
It says run a migration:
def self.up
create_table :users do |t|
t.column “username”, :string
t.column “password_salt”, :string
t.column “password_hash”, :string
end
end
And then create a form:
<% form_for @user, :url => { :action => “signup” } do |f| %>
<%= f.label(:username, “username”)%>
<%= f.text_field(:username) %>
<%= f.label(:password, “password”)%>
<%= f.password_field(:password) %>
<%= f.submit(“Sign Up”)%>
<% end %>
#Note that he’s using the now defunct start_from_tag
Problem is because I don’t have a password field in users table in
database, I think it gives undefined method error for password when I
pass as argument in the password_field() method. However, in the book,
he does exactly that and it works for him.
Is there anything I’m doing wrong?
The example should never have worked, unless he’s relying on some
particular authentication library (or an attr_accessor call) to create
the password method.
However, you’re doing two things wrong here:
- Following an outdated book
- Trying to roll your own authentication library – just go with
Authlogic or Devise.
Thanks for response.
Best,
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
On Dec 13, 2010, at 3:46 PM, John M. wrote:
t.column "password_salt", :string
<%= f.label(:password, “password”)%>
Is there anything I’m doing wrong?
What’s your model look like? You’ll want the following in your User
model…
attr :password
And some hooks to convert that into password_hash I suppose as well…
-philip
However, you’re doing two things wrong here:
- Following an outdated book
- Trying to roll your own authentication library – just go with
Authlogic or Devise.
This is for a personal project that doesn’t require rapid development.
I’m just trying to build my own authentication system so I can better
understand the Rails environment. Like you said, perhaps he’s declaring
a setter and getter method of the User class with the identifier of
“password”. Nevertheless nowhere is it explained how to translate this
to a password hash in this book. I looked at the Advanced Recipes book
and it doesn’t cover authentication at all.