Displaying 20 results from an estimated 6000 matches similar to: "Using "validates" in Model Question on Control Flow"
2006 Jul 04
1
LoginGenerator Problem
I am trying to make a barebones login system based on this example
(which in turn is just standard RoR login) but when I enter a user name
and password, it says the login is unsuccessful every time. I am not
sure where I am going wrong. Here is all relevent information
CREATE TABLE `users` (
`id` int(6) unsigned NOT NULL auto_increment,
`login` varchar(20) NOT NULL default
2006 Apr 13
1
Model is not a class
I''m trying to specify a model in a controller, but rails gives me
"Account is not a class", where Account is my model name ...
This is my model:
class Account < ActiveRecord::Base
validates_presence_of :email, :email_confirmation,
:username, :password, :password_confirmation
validates_format_of :email,
:with =>
2006 Jan 20
3
Is there a way to validate a model w/o saving it?
I have some code in my controller which looks like this:
if request.post? and @account.save and @user.save
...
end
and in my Account and User models I have many :validates, like so
account.rb
validates_presence_of :subdomain, :on => :create
validates_uniqueness_of :subdomain, :on => :create, :message => "is
already being used"
validates_exclusion_of
2008 Aug 01
0
Help with Access Control
Hi,
I am following the excellent tutorial http://www.railsforum.com/viewtopic.php?id=14216
(post 5) on how to implement an access control feature i.e. only a
friend is allowed to view a profile of a particular member. I am not
using the restful authentication plugin as the author is using to
implement the authentication feature (post 1) in the tutorial. All I
am interested in is the post 5
2006 Jul 24
6
error_messages_for not working
I have the following code and I am not able to get it working. The error
message is not coming on the top, it is just getting displayed on a
different page if I dont have the rescue block commented at the bottom.
Model: user.rb
require "digest/sha1"
class User < ActiveRecord::Base
validates_presence_of :eaddress, :fname, :passwd, :pcode, :country,
:day, :year, :month, :gender,
2006 Apr 26
1
Possible acts_as_authenticated bug (or rails)
The code that comes with the plugin uses a method that looks like this:
def password_required?
crypted_password.blank? or not password.blank?
end
with validations that look like this:
validates_presence_of :password, :if =>
:password_required?
validates_presence_of :password_confirmation, :if =>
:password_required?
validates_length_of
2006 Dec 16
2
Validate some fields only on object creation, not update
I''m having a problem with my User model. Originally I had alot of
validation, including this:
validates_presence_of :password_confirmation, :password
validates_length_of :password, :within => 4..50
validates_confirmation_of :password
However, this made it impossible to edit a user without setting his
password, which I don''t want. So I tried to isolate the above
validations
2006 Jul 16
0
Problems with validates_lenght_of
I''m building a login system, and I want users to be able to update their
password, first name and last name after signing up. So, when signing up
password can''t be nil, and it must be between 6..20 characters long. However,
on update, the user can choose to leave the password field empty (but fill in
other stuff, like first name) and then I want the User model to not update
2007 Oct 23
11
validates_confirmation_of not working?
I just can''t get validates_confirmation_of working for the life of
me!...
It''s not the first time I''m having problems with it but I just never
understand why!... This time I pretty much followed *exactly* the
example in Agile Rails Development and still...it just won''t work! I put
2 different passwords in the form and it doesn''t trigger an error,
2006 Jul 17
19
updating model
hello,
i am writing a simple user login system.
when registering a user account, i have two field:
password
password_confirmation
which are validated using
validates_presence_of
validates_confirmation_of
and these are then used to generate a password hash which is stored in
my database
when i want to update the record (without changing the password and
entering new values for password and
2008 Jan 16
4
ActionController::InvalidAuthenticityToken in LoginController
Hi,
I''m having a problem trying to get a login controller working. When I
try and post to my login controller I get the following error:
ActionController::InvalidAuthenticityToken in LoginController#login
login_controller:
class LoginController < ApplicationController
def login
case request.method
when :post
if @session[''user''] =
2006 Apr 04
3
model validates twice in tests, produces duplicate errors
In my unit tests for my User model, I''m testing some validation cases.
What is really strange, and driving me crazy, is that in the unit
tests, it seems like the save method is causing my validations to
execute twice, and produce duplicate error messages. This is making my
tests fail (because I''m checking for the number of errors that I
expect). In the web browser, only one error
2006 Apr 14
1
Validating Existing Models
I''ve got a user object which has quite a few attributes mapped to the
database. As of right now I''ve got some validations in the model like:
validates_presence_of :password, :message => "You must specify a valid
password."
validates_confirmation_of :password, :message => "Password doesn''t match
the confirmation."
validates_presence_of
2006 May 18
6
Newbie:problem when using validates*
Hi,
I have performed the cookbook tutorial. Before tailoring the views and
controllers, when I put in the model recipe.rb:
validates_uniqueness_of :title
validates_length_of :title, :within => 1...20
And I tried to introduce some new recipe without the above conditions I
got the message:
---------------------------------------------------
New recipe
1 error prohibited this category from
2006 May 18
0
[newbie]problem when using validates*
Hi,
I have performed the cookbook tutorial. Before tailoring the views and
controllers, when I put in the model recipe.rb:
validates_uniqueness_of :title
validates_length_of :title, :within => 1...20
And I tried to introduce some new recipe without the above conditions I
got the message:
---------------------------------------------------
New recipe
1 error prohibited this category from
2006 Nov 06
4
Confirmation fields on forms
I am unsure how to use a confirmation only field in my forms. The
perfect example is when registering a user, you want them to type their
password twice but you only want to have one record for it.
The form fields;
user[password]
user[password_confirmation]
form posted;
user = User.new @params[:user]
Error is thrown because there is no method for password_confirmation.
--
Posted via
2005 Dec 29
7
belongs_to causing NoMethodError exceptions ... ?
I''ve got a really strange problem using belongs_to. I apologize in
advance for the length... this is going to take a while to explain.
Basic idea: Creating a User requires that the user enter an email
address and activation key that matches an existing PendingUser.
After creating the user successfully, that pending user should be
marked as "used".
The problem:
When I
2005 Oct 14
7
validates_confirmation_of not working
Hello, I''m having a weird problem in my user model. For the
change_password method I have the following:
def change_password(oldpass, newpass, confirmation)
oldpass = self.class.myhash(oldpass)
reload
passhash = self.password
self.password = newpass
self.password_confirmation = confirmation
if valid? and oldpass == passhash
save!
else
# valid?
2006 Mar 29
5
How to skip password validation when updating other fields?
Besides the hashed password, which is saved to db, I have two
password-attributes in my User model:
attr_accessor :password, :password_confirmation
I have validations on these attributes, and I need them to work both on
create and update, since I have pages for changing and resetting the
password.
Now when I want to update just the user''s login name, I guess I have the
next
2006 Jan 20
8
validates_confirmation_of not working
is there any special requirement for validates_confirmation_of ? I am
trying to make sure 2 passwords are equal (cleanly the rails way)..
In my view i have two fields with id user[password] and
user[password_confirmation].
in the model i have
validates_confirmation_of :password, :message =>"Passwords do not match "
Am i missing something here ?
thanks
adam