On 11/29/05, Michael T. email@example.com wrote:
I have a controller named Login, a model named Login and a table named
logins (why did Rails insist that this had to be logins, instead of
login?) and the controller looks like this:
Plural table names are a convention in Rails. Rails is convention based
if you follow the convention it makes life easier. Not that you have to
though. Look at the docs if you want to call your table / primary key
class LoginController < ApplicationController
email varchar(96) default "",
real_name varchar (64) default ""
Now what I can’t figure out right now is how do I connect to the
database the “rails way,” and check to see if formVars[“username”] and
formVars[“password”] are valid according to the entry in the database?
In general, in your view, you would call the text fields like
<%= text_field ‘login’, ‘username’ %>
<%= password_field ‘login’, password’ %>
This makes @params[:login][‘username’] and @params[:login][‘password’]
available to your controller.
The general format for the text_field is <%= text_field ‘object’,
%> If you follow this convention rails will automagically fill out the
if it’s not filled out correctly. It will also display and highlight
with the scaffolding.
To confirm that the password / username is valid, you could use in your
@login = Login.new(@params[:user])
These will tell you if your model is valid acording to your validate_xxx
statements in your model.
class Login < ActiveRecord::Base
validate_presence_of :username, :password
validate_format_of :email, some regex
There is pretty good docs on rails wrt this, and there is also plenty of
discussion on this list.
Also, would anyone recommend the book Agile Web D. with Ruby
on Rails as a comprehensive guide to all things Rails?
Definitely I would recommend this book. But you should also supplement
with some research into Ruby.
Whys poignant guide http://poignantguide.net/ruby/ - This is a strange
Gives a good list of ruby related docs to start with.