similar to: adding an attribute to a ActiveRecord::Base instance

Displaying 20 results from an estimated 10000 matches similar to: "adding an attribute to a ActiveRecord::Base instance"

2006 May 09
1
Session mgmt. bug - ActiveRecord & MemoryStore session store
Windows XP Pro Rails 1.1.2 I need some help verifying this behavior that I''m seeing. BUG: Objects in session which are descendants of ActiveRecord::Base lose attributes on subsequent requests when using CGI::Session::MemoryStore. TO REPRODUCE: 0) Set up MemoryStore as the session database manager in the appropriate environment.rb file in config 1) Create a model object X that
2006 Apr 07
0
Custom Non-ActiveRecord Classes or not...
Say I want to gather info from various Models... Files, Folders, and put them into a ''display'' Object DisplayFilesystem that will standarize the info from both tables (for display only)... Class DisplayFilesystem attr_accessor :item_id, :name, :type, :description, :date def initialize @item_id = @name = @type = @description = @date = nil end end So in the code side
2006 Jun 02
1
controller instance methods available in rhtml?
In rhtml, you have access to controller. I am trying to set an instance var in my controller, then retrieve it in my form display. I know I could do this through one of the hashes I have access to, but I''m trying to understand why I can''t do it this way. No matter what, when I try to output from my rhtml either <%= controller.whynot || ''Unknown'' %> or
2009 Sep 09
1
Paperclip attachment to AWS - ActiveRecord::AssociationTypeMismatch Going Nuts!
Hi, I have been trying to do this for a few days now and cannot figure it out. I would be very grateful is anyone can help me I am trying to upload an attachment to AWS, S3 using paperclip, however every time I keep getting this error: ActiveRecord::AssociationTypeMismatch in ProjectController#create_notice Graphic(#37649720) expected, got Tempfile(#27280470) RAILS_ROOT:
2009 Sep 10
2
Paperclip attachment to AWS - ActiveRecord::AssociationTypeMismatch
Hi, I have been trying to do this for a few days now and cannot figure it out. I would be very grateful is anyone can help me I am trying to upload an attachment to AWS, S3 using paperclip, however every time I keep getting this error: ActiveRecord::AssociationTypeMismatch in ProjectController#create_notice Graphic(#37649720) expected, got Tempfile(#27280470) RAILS_ROOT:
2006 Apr 30
0
populating model attribute from one of many lists
I have a model named Project which contains a name attribute, and I have a second model named Booking which has, among other things, a date and a Project. (has_many :bookings, belongs_to :project). When a user creates a new Booking, they have the option of using an existing Project or creating a new Project. As an added complexity, when choosing from existing Projects, they can either choose from
2005 Dec 17
1
lost in an ActiveRecord::StatementInvalid
I have an error I don''t know how to debug. I am adding the login suport in Depot (the example in the RoR book) and LoginController#add_user throws ActiveRecord::StatementInvalid in an innocent /login/add_user GET request. The trace goes down to a call to SQLiteAdapter#table_structure, and the source code suggests what''s happening is that "PRAGMA
2006 Jan 29
3
Persistent form data (using sessions?)
Hi all, I''ve been struggling with this problem for the past 2 days and still haven''t found a good solution - any help would be appreciated! I have a ''list'' page that lists all products from a DB. On top of that listing I have a little box where the user can specify ''filter'' parameters (eg, book name equals ''foo''). The
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 Jun 11
1
Activerecord attribute without db column
Hi, I''ve a model that is stored to the db, but just one of its atribbutes doesn''t have a corresponding column on the table (it is used just for a calculation and still requires validation). I''ve been succefull by doing what is explained in http://rails.techno-weenie.net/tip/2005/11/19/validate_your_forms_with_a_table_less_model But I get an error of a non-existent
2011 Nov 24
5
ActiveRecord::AssociationTypeMismatch
Hi to all, I have this error and I don''t understand why. I have three model, Image and Playlist and PlaylistItem. Everything works fine. The app should work also a XML REST service. When I made this call I obtain this XML because the playlist don''t contains images: GET http://0.0.0.0:3000/playlists/7.xml <playlist> <id>7</id>
2008 Sep 17
2
AR: add attribute to model
Hi! Well, I thought this was easy, but for some reason it won''t work... Here is what I want to do: I am working on an API to a large database. The basic mapping is done, but I want to implement some convenience methods that take information for one object and does some calculations with it. The result should be accessible as attribute. So in a simple example: We have an object that
2006 Aug 11
2
Accessing belongs_to objects from a form_for context
In a form_for context, is there a way to access objects that are related to the primary object with a belongs_to? I think an example will serve best: class User < ActiveRecord::Base belongs_to :person attr_accessor :username end class Person < ActiveRecord::Base has_one :user attr_accessor :first_name end <% form_for :user do |form| %> <%= form.text_field
2009 Sep 24
5
Non-ActiveRecord based model being passed as string?
I have a model that looks like this (with various other methods) class HsdPair attr_accessor :hsd def initialize(hsd) @hsd = hsd @current_display = 0 @has_changed_flag = false end end After initializing this object in the controller @hsd_pairs = HsdPair.new(@job.hsd_pairs) using it in the view various times and in various ways, when I try to pass this object back to the
2011 Jan 02
0
"Confirmation" succeeds when the *_confirmation attribute was neglected from the Model.
<pre> models/user.rb: # Oops! I forgot to add the :password_confirmation attribute! class User < ActiveRecord::Base attr_accessor :password attr_accessible :password #, :password_confirmation validates(:password, :confirmation => true, :presence => true) end activemodel/lib/active_model/validations/confirmation.rb: 3 # == Active Model
2006 Dec 08
2
trouble using ActiveRecord classes
I''ve been trying unsuccessfully for the better part of today to write a worker that can use by ActiveRecord model classes. The bizarre thing is that worker just stops at the point accessing the database connection. An exception isn''t raising, it just dies. My worker class is below, I''ve interspersed log messages throughout to try to determine where it is dying. =====
2006 May 25
0
ActiveRecord::Base errors attribute - is it gone?
Trying to do some error handling a la AWDWR and trying to manipulate the errors collection in a model object. But there isn''t an errors attribute in ActiveRecord anymore it seems. Is there still a handy way to specific model validation errors in a built-in container? Thanks, Wes -- Posted via http://www.ruby-forum.com/.
2007 Mar 21
2
A real puzzler: attr_accessor / create incompatibility?
Greetings, I have a problem with attr_accessor and create seemingly being at odds with each other in my environment. Here is the setup: A simple class representing a US State (say, Maine for example): class State < ActiveRecord::Base attr_accessor(:name, :code) end In an IRB session, I type the following and receive the response included below: >>
2010 Aug 13
2
Rails 3 / ActiveModel for Credit Card information?
When submitting billing information in the past I''ve always used attr_accessor for credit card details as they should not be saved in the database. In addition I always end up storing the card expiration date so that the date form helper works correctly. With Active Model it seems logical to create a CreditCard class to hold this data instead. **1st issue.** It seems there still
2006 Jul 27
5
Calculate methods on attr_accessor objects
Is it possible to use the calculate methods (sum, etc.) on attr_accessor attributes? Ie: Class Item < ActiveRecord::Base attr_accessor :total_cost def total_cost @total_cost = self.cost_unit * self.amount end calling Item.sum(:total_cost) or Item.sum(''total_cost'') both return a unknown column ''total_cost'' mysql error. I thought that active