similar to: Strange thing with ActiveRecord ??

Displaying 20 results from an estimated 2000 matches similar to: "Strange thing with ActiveRecord ??"

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 Jun 13
0
Best way to format attributes during visualization/editing
Hi to everyone, My name''s Carmine and I''m a rails newbie. So, here''s my newbie question :) I have a model with one attribute named "kind" of type integer. This attribute can assume values within the range [0..5]. Each value has a "verbose" representation e.g.: 0 => grain, 1 => liquid ... To visualize the verbose representation I''ve
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
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
2008 Jan 30
1
Import XML in mysql
Hi, I am using scrubyt for scraping a webpage. The output is xml: Example: <root> <item> <item_name>Canon Vertical Battery Grip BG-E3 For EOS Digital Rebel XT</item_name> <price>$179.00</price> </item> <item> <item_name>Canon Vertical Battery Grip BG-E4 For EOS 5D</item_name>
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"]
2009 Jun 12
2
Automate a data load and merge
Hi R list, I would like to automate, or speed up the process from which I take several separate datasets, stored in .csv formate, import and merge them by a common variable. So far I have greatly sped up the loading process but cannot think of a way to automate the merger of all datasets into a common data.frame. My apologies if this has been covered, any R search suggestions are
2006 Mar 10
5
PDF::Writer Simpletable Iteration
Hello All: I have been working with <a href="http://ruby-pdf.rubyforge.org/pdf-writer/index.html">Austin Ziegler''s PDF::Writer</a> as a means to produce PDF documents from my Rails app. I am stumped on how to iterate through a collection of items and output them in a table format. The way I have tried it so far only returns the last item in the collection -
2007 Aug 23
0
active scaffold polymorphic model
Hi I am trying to use active scaffold to build a polymorphic model . I have a number of models that can be featured and I have a Feature model that belongs_to :item, :polymorphic => true In my config.columns I include :item_type and item_id, I also added :item_name to show the name of the record in the form. In the form, when a type of model is selected I populate the select box for