Displaying 20 results from an estimated 3000 matches similar to: "Make AR setter methods private?"
2007 Jan 26
7
How to protect attributes from being updated?
Hi!
I''m new to Rails!
Rails rox!
1 quesion so far:
I have :email attribute in User model.
I dont'' want :email to allow to be updated.
How do i do this with Rails?
Do I have to implement required validation manually?
Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails:
2010 Jun 11
2
AR after_initialize quandry
I have a case where I am abstracting the creation of models. After a
fair bit of indirection, I eventually get around to making a .new call.
I need to be able to pass params to that .new call.
I know I can''t use def initialize() in an AR model (rather frustrating).
So, I have found some references to after_initialize, but that doesn''t
work either.
I see several threads on
2007 Jul 25
5
set_default_values rocket science - continuing after_initialize/after_find misfeature
Just starting a new thread so that it''s easy to follow.
I just submitted a patch at trac to add a new class method called
"set_default_values" ( not a great name I think ), which lets you do
all kinds of crazy stuff with setting default values.
This ticket is at http://dev.rubyonrails.org/ticket/9093 and example
pastie is at http://pastie.caboo.se/81925
It also lets you make
2007 Nov 26
6
Model setters, override attribute=(attribute)?
Hi,
I have a model similar Basket shown below. If customer_type is set
then it should also set customer to nil. Likewise, if I set customer,
it should inspect the customer_type attached to the customer and set
accordingly within Basket. However implementing it as below doesn''t
seem to work.
Am I missing a better way to achieve this? I had also considered using
a before_save
2009 Jun 22
4
modal validation not works
Hi everyone,
i have 20 fields in users table.
in my admin profile module the admin can modify his infomation.
but only 12 fields he can able to modify.
so in my controller
if params[ :profileinfo ][:first_name]
@profileinfo.update_attribute(:first_name,params[ :profileinfo
][:first_name])
end
the above simply saves what i enter into the field.why it doesnot
consider the modelvalidation.
2006 Apr 21
2
Using before_create and conflicting setter method...
Hi,
I am having trouble using before_create when I have an specialized
setter method:
before_save :set_campaign_start
#-----------------------------------------------------------------------
-------
def set_campaign_start
self.campaign_start = Time.now
end
# We want the date to always start at midnight
2007 Aug 15
8
Extra Options to Heckle
I''ve tried running Heckle with rspec on some of my classes, but keep
getting (what I believe to be) an infinite recursion. Is there some
way to supply extra options to heckle via. rspec?
Scott
2007 May 21
7
How do I stop a column being updated by model.save?
One of my models has a column that is updated very frequently from a
separate process, so it is important that when a record is saved in
rails, this column should be left alone. In the update method of the
controller I have:
@record = MyModel.find(params[:id])
@record.update_attributes(params[:my_model])
params[:my_model] doesn''t have a reference to the column I''m talking
2010 Apr 18
1
Getter and Setter with non DB property
Hi,
I can''t find how do i created a getter and setter property for a non db
property. what i have done isnt working, i have a cnt mass assign error.
Here is what i''ve done:
attr_accessor :creator_is_participant
def creator_is_participant
@participe
end
def creator_is_participant=(participe)
if participe == true
@participe = true
else
@participe
2007 Oct 13
4
Chapter 9
Hello,
I''m currently stunk on this issue for few days and I do not know how
to get it fixed.
The system always raises this error message :
order is closed
and here is my order.rb:
class Order < ActiveRecord::Base
include ActiveMerchant::Billing
before_validation :set_status
attr_protected :id, :customer_ip, :status, :error_message, :updated_at, :created_at
attr_accessor
2006 Jun 01
1
Automatted Getter/Setter
Hey..
So I have a model that has a lot of number fields. Each of these go
through a process when read in and read out to add/remove commas
(between every three numbers) to make them more readable.
The getter I currently have is like this:
def sale_price
Listing.insert_commas(read_attribte (:sale_price))
end
and the setter is:
def sale_price=(price)
write_attribute(:saleprice,
2006 Jun 07
2
Problem with a setter that converts euros to cents
Hi,
I have some problems with an application where I''m using custom
accessors to do currency conversions. In my model, I have a price
attribute in the database that stores the value in cents, to avoid
future problems with float arithmetic and round. But at the views, I
would like to show the price in euros, with decimal for the cents. So
I defined a new attribute called price_in_euros,
2009 Aug 17
1
Problem with setter override on ActiveRecord
(This message was originally written on StackOverflow -- the
formatting is much prettier there --
http://stackoverflow.com/questions/1283046/problem-with-setter-override-on-activerecord)
This is not exactly a question, it''s rather a report on how I solved
an issue with write_attribute when the attribute is an object, on
Rails'' Active Record. I hope this can be useful to others
2005 Nov 27
1
Comparing field's old value to new value
I want to expire caches if a certain field of an item changes. How can I compare the item field''s
old value to its new value (in the create, or after_save, etc. method)?
thanks
csn
__________________________________
Yahoo! Mail - PC Magazine Editors'' Choice 2005
http://mail.yahoo.com
2008 Apr 04
5
First call to worker method doesn''t work
I have a worker as follows:
class SampleWorker < BackgrounDRb::MetaWorker
set_worker_name :sample_worker
def create(args = nil)
# this method is called, when worker is loaded for the first time
end
def my_method
# Deliver test e-mail message
Notifications.deliver_message(1, "DM")
end
end
I have a rails controller that calls the following code:
worker =
2006 Dec 02
3
Scoping expectations and more ...
Hello!
I''m new to Mocha and through experimentation I found out something
that is not explicitly stated in the documentation: If you need to
mock the same function call with different parameters and results, you
can set the scope of expectations with a begin ... end block.
I also made up an example on how to expect more than one function call
with different parameters and return values.
2006 Jun 07
1
Setter that converts a float attribute to integer
Hi,
I have some problems with an application where I''m using custom
accessors to do currency conversions. In my model, I have a price
attribute in the database that stores the value in cents, to avoid
future problems with float arithmetic and round. But at the views, I
would like to show the price in euros, with decimal for the cents. So
I defined a new attribute called price_in_euros,
2006 Feb 21
11
helper for models?
Is there such a thing?
I have some duplicate methods in my models, can I place them somewhere
and call them in to my models, thus keeping DRY?
--
Posted via http://www.ruby-forum.com/.
2010 Aug 10
3
ActiveRecord::UnknownAttributeError: unknown attribute: <script type
Has anyone seen this happening to their apps?
I''m starting to get errors like this come across from one of my apps:
ActiveRecord::UnknownAttributeError: unknown attribute: <script type
The parameters being sent are:
{"user"=>
{"email_confirmation"=>"someone-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org",
2006 Jul 06
2
Custom init. of ActiveRecord objects - best practices
All,
I''m wanting to initialize an ActiveRecord object.
I understand that there is a method called after_initialize that appears
to get called right after the ActiveRecord object is instantiated.
Is after_initialize a Ruby thing or a Rails thing?
Where is after_initialize documented?
Can I pass parameters to it? If so, how?
I want to initialize the "belongs_to" attribute of