Displaying 20 results from an estimated 6000 matches similar to: "Getter and Setter with non DB property"
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,
2012 Sep 09
2
mattr_accessor inside a class
Rails extends Ruby with mattr_accessor (Module accessor). As Ruby''s
attr_accessor generates getter/setter methods for instances,
mattr_accessor provide getter/setter methods at the module level. In
below example, you see that mattr_accessor declared in the class
context of LookupContext. It''s declared in class, not module. However,
modules are defined in LookupContext, for
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 Apr 03
7
Getters and setters problem?
Hi list,
first evening of playing with rails, so please forgive me if I ask
something stupid. ;-)
I created a User model and tried to use ActiveRecord callbacks to
convert the password to sha1 just before saving it. For some reason
postgresql gives me a error because the given password is null. To
test even further I tried to change :login too, same error happens,
:login is empty too.
I am sure
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 Jul 13
4
Does text_field go directly to attributes hash in AR object?
All,
I''m having a hell of a time figuring out what is going on here.
I''m trying to override one of my getters so that I can format it a
certain way in my form. But I can''t seem to get text_field to call the
appropriate method on my object.
So here''s my getter:
public
def FAX
fax = read_attribute(:FAX)
puts fax
2011 May 26
0
Reference Classes: getter and setter functions/methods and possible shortcuts
Hi everyone,
just wanted to ask what's the smartest/recommended way of defining
getter and setter function *shortcuts* (i.e. something like "[", "[<-")
for Reference Class objects?
Or is it desired to not use this stuff, but define methods like
'obj$getSubset(row=1:3, col=1)' and 'obj$setSubset(value=x)' instead?
I have some example code that might
2007 Dec 04
10
Unexpected message on :attr_accessor
This may be a dumb noob issue, but I haven''t found any answers while seaching
the forum--
I have a controller method
def edit
@user = User.find params[:id]
@user.password_confirmation = @user.password
end
The User class has an "attr_accessor :password_confirmation" definition (so
"password_confirmation" doesn''t exist in the users table). My spec
2011 Jul 30
22
Question about Helpers
Studying the RoR 3 Tutorial book by Michael Hartl
and on page 345 there''s the code inside the SessionsHelper:
_________________________________________________________
module SessionsHelper
def sign_in(user)
cookies.permanent.signed[:remember_token] = [user.id, user.sault]
self.current_user = user
end
end
__________________________________________________________
What is the purpose
2011 Mar 07
3
difference between attr_accessor and attr_accessible?
Hi,
What''s the difference between attr_accessor and attr_accessible?
Is attr_accessor to create a virtual variable/object and attr_accessible
makes it accessible? Do you need attr_accessible if you already have
attr_accessor?
Thanks!
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails:
2008 May 18
4
[LLVMdev] Opaque type usage to represent foreign types
In my project I have a group of foreign types (C++ classes) that I
want to use, but don't want to represent as structs within LLVM. For
example, for each field in each C++ class I have a setter and getter
function that I'd like to use. The setters and getters are "extern C"
functions to avoid problems with C++'s name mangling.
After going over the documentation it
2006 Jul 14
1
Weird validation problem
I have a field called Fax in my model. I store it as a 10-digit number
with no other characters but I display it as a nicely formatted phone
number. I have a validation on it like this:
validates_format_of :Fax,
:message => ''number should be formatted using (XXX) XXX-XXXX'',
:with => /^\(\d{3}\)\ ?\d{3}-\d{4}$/
If I put 1234567890 (10 digits) in my field, the
2007 Dec 16
4
Make AR setter methods private?
Hi,
I have a AR model that I want to limit changes to be only via instance
methods that I''ve added.
How do I prevent my other sw from setting the instance''s attributes?
I know about #attr_protected and #attr_readonly. But the first leaves
the individual setters as they were and the second stops all changes.
I want something like "attr_private"
Thoughts?
Thanks,
2006 Jun 04
1
Problem with instance variables
Im developing a User model for my application (newbie stuff, but I have
to start somewhere). I followed the tutorial at
http://sonjayatandon.com/05-2006/how-to-build-a-secured-web-application-with-ruby-on-rails/
and decided to add an email field. The problem is that the email is not
being saved on the database and I end up with two email variables:
@email and email.
validates_presence_of
2015 Nov 20
1
Good practice for naming classes, builders, attributes, getters/setters for object composition
Hey everyone,
I am developing a package and I am wondering if there is a good practice
for naming classes, builders, attributes getters and setters when dealing
with object composition. I know that it is usually a good practice to give
to the builder the same name as the class and, if possible, to avoid to use
upper case letters. My problem is that, when I build an object containing
an other
2008 Apr 25
3
[ANNOUNCE] Samba 3.2.0pre3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Release Announcements
=====================
This is the third preview release of Samba 3.2.0. This is *not*
intended for production environments and is designed for testing
purposes only. Please report any defects via the Samba bug reporting
system at https://bugzilla.samba.org/.
Please be aware that Samba is now distributed under the version 3
of
2008 Apr 25
3
[ANNOUNCE] Samba 3.2.0pre3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Release Announcements
=====================
This is the third preview release of Samba 3.2.0. This is *not*
intended for production environments and is designed for testing
purposes only. Please report any defects via the Samba bug reporting
system at https://bugzilla.samba.org/.
Please be aware that Samba is now distributed under the version 3
of
2008 Jun 10
4
[ANNOUNCE] Samba 3.2.0rc2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
=================================
Release Notes for Samba 3.2.0rc2
June 10, 2008
=================================
This is the second release candidate of Samba 3.2.0. This is *not*
intended for production environments and is designed for testing
purposes only.
2008 Jun 10
4
[ANNOUNCE] Samba 3.2.0rc2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
=================================
Release Notes for Samba 3.2.0rc2
June 10, 2008
=================================
This is the second release candidate of Samba 3.2.0. This is *not*
intended for production environments and is designed for testing
purposes only.
2006 Nov 04
2
Possible to use attr_reader/writer in model?
I have some properties that I want setable externally, but readable only
internally. I''ve played around with attr_writer (and attr_reader
separately) but can''t figure out how to get either to work. I can do
what I want using attr_accessor, or just straight out defining the prop
setter method. Anybody know how to use attr_writer or attr_reader with a
model?
You da man,
Joe