Displaying 20 results from an estimated 4000 matches similar to: "question about enforcing constraints in the model"
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
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
2008 Jun 20
15
before_save model callback rspec testing
hi all,
i''m learning rspec and i can''t figure out how to test if a callback is
executed in a model.
my model code is:
class User < ActiveRecord::Base
before_save :encrypt_password
...
def encrypt(password)
self.class.encrypt(password, salt)
end
thanks a lot,
cs.
--
Posted via http://www.ruby-forum.com/.
2006 May 04
2
validates :on 2
Hello, I need to have this for :create and :login how do I do so
validates_presence_of :login, :password, :password_confirmation,
:user_name, :email, :on => :create
I do need it to be off in a number of places though
--
Posted via http://www.ruby-forum.com/.
2007 Mar 26
2
Strange Record not saved errors
I have a site with an acts_as_authenticated based login which has
started throwing up some strange errors. Until a few days ago
everything worked fine but all of a sudden ''RecordNotSaved'' errors are
popping up in my logs.
When I check the database, it looks like the record _is_ saved but I
think users get an error so I''m starting to see a lot of double/triple
entries
2008 Jun 29
3
Working around/with Restful Authentication
I''m using Restful Authentication, and the code to create a user is
pretty straight forward - there is a before_save action and a
before_create action:
before_save :encrypt_password
before_create :make_activation_code
But for some reason when I try to create a user programmatically in
the controller like this:
User.new(:email =>
2007 May 05
4
Stop words, fields, StandardAnalyzer quagmire
Hello,
I''m using: Ruby 1.8.6, Rails 1.2.3, ferret 0.11.4, acts_as_ferret from
svn stable.
I''ve had quite a day wrestling with trying to remove the use of
stopwords. The problem was that when searching for words like "no" or
"the", no results were found. I found a confusing thing behavior that
has taken me some time to figure out, and I hope sharing it
2008 Nov 26
3
New status_id in Facebook API - FIX
Hi,
I''ve had one of my application broken this morning (French time) with
this error :
NoMethodError (undefined method `status_id='' for
#<Facebooker::User::Status:0x2ad52d1c8478 @message={}, @time="0">):
It appear that Facebook API had change in the status : a status_id
node is new :
<user>
<uid>785637999</uid>
2006 Jul 03
1
how to get value from the post on the List page
Hi,
I''m new to Rails. I''m building a candidates tracking system for
recruiting. I have a List page, but instead of listing every candidate,
I only wanted to list the candidates in certain statuses. The first
time List page is hit, by default, it lists candidates in status < 9.
But on the List page, there is a dropdown where all the statuses are
listed, so that when user
2006 Jun 08
1
question about finding with :include versus nested dynamic finder (bad form? efficiency?)
I have a User model and a Status model. Each user is given a certain
status, either "Accepted", "Rejected", "OnHold", "Declined", etc. I
need to find all users with a status of "Accepted", so I''m doing the
following:
in User.rb:
belongs_to :status
def accepted_users
status_id =
2007 Nov 17
18
Syntax Problem
I admit I am stuck. I am converting a legacy php site to ROR. The old
site uses MD5, a security flaw waiting to happen. I upgraded to AAA
and am adding code in the session_controller.rb file to see if
crypted_password is blank. If it is, crypt and check the password
against the old md5 version and write it in the new crypted_password
field.
Here is my code add on before the logged_in?:
def
2006 Jan 27
1
Basic Many-to-One association
Sari,
I got the list display working without doing an explicit find.
It took a bit of a conceptual convulution to get it to work. I was
thinking of it has Many Cases have One status.
There is no support for Many-to-One so I was a bit stumped.
Then I realized you just have to turn around your thinking to say One
Status has Many Cases. Thus it is a One-to-Many relationship. That
is descriped
2006 Feb 27
4
update_attribute with Validation?
Does anyone know of a way to update individual attributes with
validation? update_attribute disables the validation checks in the
record model, so I''m wondering if there''s a workaround for this.
In my application, I want to allow the user to update some or all the
attributes without having to enter :password and :password_confirmation,
both of which are subject to
2007 Jul 02
8
Strange intermittent no search results problem
Hello,
First the specs:
ruby 1.8.6, rails 1.2.3, ferret 0.11.4, mongrel 1.0.1, mongrel_cluster 0.2.1
And the model''s aaf config:
# Ferret search engine
acts_as_ferret({:fields => {:name => {:boost => 10},
:summary => {:boost => 2},
:body => {:boost => 1, :store =>
:no},
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 Jun 07
2
Are the find_ methods strictly a SQL thing?
I''ve had a number of occasions now where I want to find something in my
model that is not on the primary object. For instance I''ve got a class
Alert that has_one Status. Status has a "label".
I want to find all of my Alert objects and order the results
alphabetically by status label.
Can I do that without going into SQL? Right now I find myself doing an
2006 Mar 23
8
DRY principle - how to implement?
Hi all!
I have ''send_status'' table which looks something like these:
id code title
1 sent Sent
2 error Sending error
3 success Success
Next I would like to associate some processed records with their
''send_status''. Is it better to use:
1)
record.status_id = SendStatus.find(:one, :condition => "code=''sent''").id
to
2006 Apr 24
8
Application Design
I have a question about how to implement a design in Rails. I will try to make this as easy to follow as possible. First, let''s say that I have an ''Orders'' table that has different statuses. The 3 statuses that I want to track are ''Submitted'', ''Approved'', and ''Purchased''.
I also have 3 users of this application.
2006 Mar 04
4
Two quick newbie questions
2 quick questions regarding authentication ...
1) the flash[:notice] on successful login looks completely wrong to me.
How should it be done?
def index
if request.post?
@user = User.new(params[:user])
authentic_user = @user.attempt_login
if authentic_user
session[:user_id] = authentic_user.id
flash[:notice] =
''Login successful! Welcome
2011 Oct 14
2
before_save :encrypt_password
I am having a problem finding the best way to make a "before_save
:encrypt_password" conditional.
I have to at times update user model attributes but each time I do this
the password is reencrypted because of the above. I need to
differentiate between when the user is first logging in and the password
does need to be encrypted, and when they are already logged in and the