Displaying 20 results from an estimated 1000 matches similar to: "before_save :encrypt_password"
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/.
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 =>
2006 Feb 10
4
before_save gotcha
Is it will known and accepted that before_save triggers should return
true? I didn''t notice this before but now I see it in the
documentation.
Here is what I''m doing in my model:
def before_save
if self.has_album?
self.visible = self.album.visible?
end
end
That results in the expected result when album.visible? is true - but
not when it is false. To make it
2009 Feb 07
5
before_save :strip_whitespace => saves with spaces
i used this private function for removing leading and trailing white
spaces from the values.that below function would be called before_save.
when i print the value after it strips.it prints string without any
spaces.but in the table fields it saves with spaces .
waht would be the problem.pls help me
class CompanyInfo < ActiveRecord::Base
before_save :strip_whitespace
def strip_whitespace
2007 Jun 27
3
acts_as_tree and before_save
We all know that acts_as_tree gives us ability to set up data in a
tree-like structure and use methods like ''parent'', ''children'' and so on.
Something I''m completely stuck on. Observe.
class Page < ActiveRecord::Base
acts_as_tree
def before_save
raise self.parent.to_yaml
end
end
Well, you''d think that it should show
2006 Jan 03
2
Stopping a save from the before_save
What''s the better thing to do in a before_save if you don''t want the
save to continue?
raise an exception, or do an errors.add or both?
Thanks,
Chris Nolan.ca
http://kweschun.com/ - Do you have a Kweschun?
2012 Nov 10
6
Suggestion: `before_save on: :create` should either work or raise an exception
There''s a small inconsistency in ActiveRecord''s callback syntax that has
tripped me up before. It wouldn''t be a big deal, but it can lead to a
silent failure. I''d like to suggest that it either be made consistent or be
made to fail loudly.
The issue is that to do something before validating, but only when
creating, you use `before_validation on: :create`,
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
2010 Sep 03
1
Action Controller Error: undefined local variable or method `current_user'
Newbie learning Rails. I''m currently on Chp9 here:
http://railstutorial.org/chapters/sign-in-sign-out#top
At the end of the tutorial, rails is erroring (see below). being new
to Rails and after having checked the tutorial... How do you resolve
this kind of error. It''s saying current_user is not defined, and it is
supposed to be defined with/Sites/sample_app/app/helpers/
2006 Aug 09
7
function before_save
Hi everybody
I would like a function as the "before_save" method in the model. But it
must be the opposite. When I take out data from the database through the
model, I want to call a function before the data are available in the
controller.
Can anyone help me?
---- >>>> thx <<<< ----
--
Posted via http://www.ruby-forum.com/.
2012 Feb 28
1
Conditional execution of javascript / embedding Cappuccino files into Rails
I have a Cappuccino app that I am integrating with a Rails backend. A
key feature of the app is authentication which is managed entirely by
rails. The way I set it up is that the cappuccino js conditionally
executes if the user is logged in, like this:
<% if signed_in? %>
<div id="cappuccino-body">
<script type="text/javascript">
document.write("Hello
2006 Aug 09
1
question about enforcing constraints in the model
I have a user model and a status model. Each user has a specific
status (accepted, rejected, declined, etc).
I have a form that allows the adminstrator to change certain options
for a user, including their status. I''m using a drop down menu
populated with the different status values, and a default option that
says "Choose a new status" with a value of "".
I want to
2011 Jun 12
3
Problem with undefined variable current_user
Hi everyone,
I''m working through the tutorial at the following link and attempting to
customise/adapt the lessons for my own slightly different application.
Link:
Ruby on Rails Tutorial: Learn Rails by Example | Ruby on Rails 3
Tutorial book and screencasts | by Michael Hartl
<http://ruby.railstutorial.org/ruby-on-rails-tutorial-book>
I''m currently trying to work
2012 May 12
12
before_save messing up
#user.rb ------> Model
class User < ActiveRecord::Base
attr_accessible :email, :name, :password, :password_confirmation
has_secure_password
before_save :create_remember_token
.
.
.
.
.
.
.
private
def create_remember_token
self.remember_token = SecureRandom.urlsafe_base64
end
end
#sessions_controller.rb ------->
2006 Jul 02
2
NoMethodError in Unit Test - Rails Newcomer
I''m working on user authentication system to get familiar with rails,
and have basically solved most of my apps problems till now. I keep
getting the NoMethodError, and can''t understand why.
Model: customer.rb
class Customer < ActiveRecord::Base
...
def self.password=(pass)
@password=pass
salt = Customer.random_string(10) if !salt?
self.hashed_password =
2009 Oct 23
0
Sanitize html with :before_save depending on logged in user
I woud like to sanitize attributes (with ''sanitize" gem) but unless the
model is being saved by admin. (Suppose this model doesn''t have any
relationship with user model)
# In model.rb:
:before_save set_html_plain
def set_html_plain
self.body = Sanitize.clean(self.body)
end
Two questions:
1) How can I check here if saving process has been initialized by
2007 Dec 26
0
before_save with acts_as_versioned
Yes, I know about the :if/:if_changed clause on acts_as_versioned
... content_changed or author_changed ....
That''s not what I''m asking about.
What I''m wondering about is something like applying the spiffy new 2.0
sanitize as a ''before_save''
--
A little inaccuracy can save tons of explanation. -- Saki
2011 Jul 19
0
Ruby on Rails Tutorial Chapter 8 Signup Success
I have written the Users controller and Spec tests correctly for the
"successful creation" in the User controller however I get the
following two errors:
1) UsersController POST ''create'' success should create a user
Failure/Error: lambda do
count should have been changed by 1, but was changed by 0
#
2006 Mar 02
2
How to get mime extension with file_column
Is there a way to get the MIME extension of a file_column field?
Here''s what I want to do (look for comment in before_save method):
class ProductFile < ActiveRecord::Base
belongs_to :product
file_column :file_name
def before_save
self.file_type = # something that returns the MIME type (e.g. image/jpeg)
end
end
TIA
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