similar to: Exploring ActiveRecord::Base#serialize

Displaying 20 results from an estimated 20000 matches similar to: "Exploring ActiveRecord::Base#serialize"

2006 May 17
6
White Screen of Death
Hello, I''ve heard these words to describe a RoR application returning an empty page. This happen from time to time even here, in the forum. That is the cause of this misbehaviour ? Is it related with something external to RoR itself ? What is the solution to avoid the WSOD ? -- Posted via http://www.ruby-forum.com/.
2006 May 08
2
Creating a "Foo has_many bars" association where bar isn''t a model.
Hi Let''s say we have model Foo. Each Foo instance can have several bars. Those bars are primitive, so they shouldn''t be models. For example, Foo might be a type of convention, and the bars might be years the convention was held in. Naively, we would have a conventions_years date, and put: has_many :years inside class Convention. But then we''d get an error, since for
2007 Jun 16
1
extending activerecord base with after_initialize
hi, i am having problems getting after_initialize for activerecord subclasses. basically, i am trying to use the guid plugin by andy singleton. i am having problems extending the class to the plugins i installed, so i figured i will just apply this to all the models in my project. i trled to add the following to my lib/ folder. my goal is to extended the activerecord class so that it uses
2006 Aug 06
2
help with method_missing in ActiveRecord
I am serializing a data object (FooData) into an ActiveRecord column (Foo). I''d like to be able to do delegate methods to the data class if the Foo class doesn''t have that attribute. So instead of: f = Foo.new f.data.item1 I''d like to do: f = Foo.new f.item1 I was hoping that I could add a method_missing method to my Foo class and call methods in the FooData class
2006 Oct 27
5
Purpose of after_initialize in ActiveRecord?
All, I have a quick question - is the purpose of implementing after_initialize to allow custom attribute initialization for AR descendants? I have been overriding initialize whenever I require custom setup of my model classes, like so: def initialize(attributes = nil) super self.Status = ''G'' end So I have a couple of questions: 1) Could I achieve the same
2006 May 27
2
ActiveRecord::Base::find_for_create_modify
Hi, for some models I found that it''s easier to share the controller new and update code just to share the view code. At the front of every such action function I have to lookup if the object already exists, if so "find" it from the database and update the "attributes=". If there is no such object, "new" it with the attributes I''ve got from the
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
2006 Jul 21
2
File.open behavior for ActiveRecord, to ensure save after manipulation?
File.open in core Ruby is nifty, in that it automagically closes the file when you''re done using/manipulating it. I''m wondering whether there''s something like that for ActiveRecord? So you can do: AR.find(23).open {|ar| ar.foo = ''bar'' ... } And ar.save would be called when the block closes. -- -Alder
2011 Mar 09
1
ActiveRecord serialize method not returning YAML array in test environment.
Hello, I''ve got a problem with deserialization of AR "serialize" method (http://apidock.com/rails/ActiveRecord/Base/serialize/class) in my tests. It just gives me pure String instead of my data Array. Example: User > AR::Base serialize :roles, Array end Console: u = User.new u.roles = ["admin", "support"] u.save # => true User.first.roles # =>
2006 Jun 26
1
ActiveRecord, instance_eval, and PStore
I''m trying to add some per-object behaviors to objects descended from ActiveRecord, by using after_initialize() and instance_eval(), like this: def after_initialize self.instance_eval(File.read(''customers/default.rb'')) end (Ultimately the file path will be dynamic, this is just proof of concept.) default.rb just contains a few method definitions like this one: def
2006 May 27
7
How should I select rows from a join-model based on more than one association?
A concrete example: We''re building a system to organize the information about workshops being held in various conventions. A convention has more than one workshop, and each workshop can be held in more than one convention. Also each workshop has a host, who is specific to a workshop being held in a specific convention. For example, Matz may host an "Introduction to Ruby"
2006 Apr 20
5
Mystified by ActiveRecord.serialize
I''m either missing a step, confused or seeing some odd behavior with ActiveRecord''s serialize feature. When I load an ActiveRecord object from the database, my serialized attribute is a YAML::Object, not the original object. My code is based on an example of this capability in the "Agile Web Dev. w/ Rails" book (p. 196). In create.sql: <code> create table
2005 Oct 04
3
serialize()
Near the end of the Sortable.serialize() method, there is a split command that splits on an underscore. What is the convention it''s following here and is it documented somewhere? Thanks, Jamie serialize: function(element) { element = $(element); var sortableOptions = this.options(element); var options = Object.extend({ tag: sortableOptions.tag, only:
2010 Dec 08
0
ActiveRecord serialize field and SerializationTypeMismatch
Hello. In one of my ActiveRecord models I specified a a serialize field: serialize :settings MyModelSettings If I understand the documentation correctly this restricts settings to the class MyModelSettings. The problem is that this is so restrictive that I even don''t know how to initialize the field. MyModel.new or even MyModel.new(:settings => MyModelSettings) everything I do
2008 May 05
0
Changing ActiveRecord serialize format to XML instead of YML
Hello, So far, ActiveRecord serialize is working great for me to save arbitrary data. I would like to know if there is a way to change the format of ActiveRecord serialize to XML instead of YML. I like the readability of YML, but I need to search serialized fields in the database. So, it would make sense to use XML because most database vendors supports XML value extraction, e.g,. ExtractValue
2008 Jul 25
1
serialize() to via temporary file is heaps faster than doing it directly (on Windows)
Hi, FYI, I just notice that on Windows (but not Linux) it is orders of magnitude (below it's 50x) faster to serialize() and object to a temporary file and then read it back, than to serialize to an object directly. This has for instance impact on how fast digest::digest() can provide a checksum. Example: x <- 1:1e7; t1 <- system.time(raw1 <- serialize(x, connection=NULL));
2006 May 13
8
Which Linux flavor for a Rails server?
Hi folks, I''m a linux noob, and I''m trying to pick a distro for my rails server. I don''t want to start a flame-war about linux distros! I''m interested in the best distribution for these criteria: 1 - Simplicity of getting ruby and rails set-up (gem updates) 2 - Stability (it is a server, after all) 3 - Support resources (community, and as a fall-back, paid
2006 May 24
1
Observer behavior differences between DEV and TEST environments ?
Hi all ! I''m having an issue and I can''t seem to make heads or tails of it. I am attempting to add an observer to a model object. I created app/models/greenback_transaction_observer.rb, inherited from AR::Observer, defined methods, registered in config/environment.rb, but things don''t work... So, I took a step back and put in the following code: class
2006 Jun 01
9
access model from controller
Hello, Rather new to RoR, so I''m not sure about the terminology and such :-/ . My question is: how could I know the model which is associated to a controller? For example: - controller class is TestController, which is a subclass of ApplicationController - associated model class is Test How could I write some code in a method of ApplicationController to dermine the current
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