similar to: Best way to format attributes during visualization/editing

Displaying 20 results from an estimated 3000 matches similar to: "Best way to format attributes during visualization/editing"

2009 Sep 23
5
Overriding AR read/write_attribute - Overridden write_attribute Is Never Called
Could someone explain this? #config/initializers/ar_attributes.rb module ActiveRecord module AttributeMethods alias_method :ar_read_attribute, :read_attribute def read_attribute(attr_name) p "read_override" ar_read_attribute(attr_name) end alias_method :ar_write_attribute, :write_attribute def write_attribute(attr_name, value)
2010 Jul 19
3
ActiveRecord override
Would really appreciate it if someone could tell me why this is happening: I override ssn method of AR class so I can encrypt/decrypt to/from the db: class Person < ActiveRecord::Base def ssn=(value) write_attribute(:borrower_ssn, Crypto.encrypt(self.encryption_key, value)) write_attribute(:borrower_ssn_final_four, value[5,4]) end def ssn # this begin - rescue can be
2006 Feb 06
7
Delaying initialization of associations until first access
Guys, Say I have the following: ----- class Person < ActiveRecord::Base has_one :house end class House < ActiveRecord::Base belongs_to :person attr_accessor :color end ----- Then I have the following code: ----- john = Person.new john.house.color = "Blue" john.save ----- What I would like to have happen, is that on first call to john.house, if house hadn''t been
2006 Aug 19
5
Form helpers don''t work with facade columns?
Hello all, I''ve been trying to use a facade column but I notice that the form helpers don''t seem to respect the facade. In the following example I''m trying to story the prices as Integer values but present them to the user as decimals. class Product < ActiveRecord::Base def price=(new_price) write_attribute(:price, Float(new_price)*100) end def price
2006 Jul 12
1
odd habtm behavior? or is it me?
Hello List, I''m a bit spent on this problem, and my code might be whack. I seem to be encountering a problem where the primary key on a join table is not being resolved correctly. I will elaborate after some code bits. I am creating the join table using migrations, and relevant model code is this: class Post < ActiveRecord::Base has_and_belongs_to_many :records
2006 May 22
2
Inserting data in a table with a varchar key field
Hi all, I have some problems inserting data into a legacy table. the key field of this table is a field named CIN which is a varchar(15). when I try insert into this table using a form (generated by the scaffold generator) I get this Error : _____________________________________________________________________ undefined method `CIN_before_type_cast'' for #<Candidat:0x370d8c8> |
2006 May 10
13
Issue in ActiveRecord generated reader methods
Hi all! I have come into a strange issue in Rails that I am hoping someone can shed some light. To make a very long story short, I have been researching how to override ActiveRecord::Base#read_attribute and write_attribute to perform security checks at the model level (influenced by the ModelSecurity generator). Shortly after implementing some code to check this behavior, I began to
2006 May 10
0
Saving extracted data
Hi there, I have a file upload form on my page that is for images. In the model I have this: def file_data=(file_data) @file_data = file_data write_attribute ''extension'', file_data.original_filename.split(''.'').last.downcase write_attribute("content_type", file_data.content_type) write_attribute("current_name",
2009 Mar 27
1
UTF8 postgres args saving issue
Hi, All I have an encountered an issue where the args field is not saved correctly to the database. I encounter an error like this: ActiveRecord::StatementInvalid (RuntimeError: ERROR C22021 M invalid byte sequence for encoding "UTF8": 0xcb3a H This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by
2007 Mar 30
1
write attribute coming from where?
There are datatypes that need to be converted back and forth from a string representation: they need to be parsed both coming from the database, and coming from elsewhere like views. Dates are an example, and I recently needed to implement a more forgiving converter for decimal numbers. So we have here at least two flows of execution, for example: post.date = "22-jan-2007"
2006 Aug 01
0
Validation of facade columns
I''m having difficulty understanding how to make validation of facade columns consistent with validation of other active record columns. To illustrate this, I''m going to extend the facade column example discussed on pp. 284-5 of AWDR. Let''s say that there is a "rectangles" table that has width and height columns. For some unknown reason, width is stored in
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
2006 Jan 14
0
Overriding column accessors?
Hi, Is it possible to override the default accessors that are created by Rails? For instance I had this User object which has the column headings "password" and "salt" in its SQL table. I did manage to override the setter accessor for password by using def password=(new_password), but when I tried doing the same for the reader by using a def password method (to return a
2006 Jan 19
0
Strange thing with ActiveRecord ??
Hi I am probably missing something, so please help: I have a table called ''zipped_responses'' with an ''item_names'' varchar column. I want to create a comma separated string of ''names''. I have an ''add_item_names'' method which takes a ''name'' and put it at the end of a string with a preceding comma. The
2005 Sep 22
1
ActiveRecord DateTime mapping
Hye, I try to store DateTime as integer (seconds) in my database (MySQL). I''d like to convert seconds to DateTime in the ActiveRecord object to handle it easily in my views. I try to play with callbacks or with method dedicated to my attributes for eg. def fetched upd = nil v =read_attribute(:fetched) if (v) upd = DateTime.at(v) else upd = DateTime.now end end def
2010 Dec 30
6
validates_inclusion_of doesn't match constant
Hello, I have a model Model: SPECIAL_FEATURES = %w(none top) class Model validates_inclusion_of :special_feature, :in => Model::SPECIAL_FEATURES, :on => :create, :message => "special_feature %s is not defined" belongs_to :team def special_feature attributes = attributes_before_type_cast if attributes["special_feature"]
2006 Nov 04
0
write_attribute trouble
Can anyone clarify something for me? I''ve been having a hard time with write_attribute. If I do (for instance in a callback): write_attribute(:user, user) Is obj.user_id set automatically too? And viceversa, if I do: write_attribute(:user_id, user.id) Does that set obj.user for me? Doesn''t seem like it''s doing that for me. Anyone understands exactly what
2016 Nov 30
1
slow directory access, convert_string_internal: Conversion error: Incomplete multibyte sequence
I think the issue may be related to the broken trusts. First of all only two people had specifically reported issues which meant for most people it was acceptable. Then I noticed that some directories seemed slower than others. If I ssh'd into the server and checked permissions, listing permissions on most directories was quick (under 2 second.) On directories that allowed
2005 Apr 27
5
Eager load mysteriously deletes records
Hi This looks like a bug in ActiveRecord. I am messing with eager loading (on 12.1) and all of a sudden records started disappearing from a table (and I am not doing anything delete related)!! The following line works OK:- @todos = Todo.find(:all, :include => [ :whens],:order => "position ASC") The following line is mysteriously deleteing :where rows from the DB after
2009 Jul 13
1
[PATCH] Use volume key instead of path to identify volume.
This patch teaches taskomatic to use the volume 'key' instead of the path from libvirt to key the volume off of in the database. This fixes the duplicate iscsi volume bug we were seeing. The issue was that libvirt changed the way they name storage volumes and included a local ID that changed each time it was attached. Note that the first run with this new patch will cause duplicate