similar to: AR: add attribute to model

Displaying 20 results from an estimated 30000 matches similar to: "AR: add attribute to model"

2005 Dec 17
2
Storing an object in the db
I''ve asked this before, but never got a working response. I''d like to store an object inside a binary field in my db. So I''d have a class like this class MyAwesomeClass def do_something_awesome ... end end then class MyRecord < ActiveRecord::Base end the table my_record would have a binary field, my_object, that would store an object of
2006 May 09
1
Reusing a model to form and link_to.
Hy guys, Inside my app I have a form which contains user information. Sometimes a have a form with a text_field as above: <%= form_remote_tag(:html => { :action => url_for(:controller => "my_controller", :action => "my_action") }) %> <%= text_field(''my_object'', ''my_parameter'', :maxlength =>
2010 Mar 24
2
Mock "Consent_6335" received unexpected message :marked_for_destruction? with (no args)
I have a mock object (Person) that is associated with another object (my_object) through a belongs_to association. When I check whether my_object is valid (my_object.should be_valid), I am getting an error like the following: Mock "Person_6338" received unexpected message :marked_for_destruction? with (no args) Checking the list of methods on the mock,
2007 Dec 08
3
Uploading photos using facebook & attachment_fu
Hi All, I''m trying to use a form to upload a photo that I will save using attachment_fu. I''m very new to Facebookr so I apologize if this is covered somewhere, but I''m kind of stumped. Here''s what I''m doing now: <% facebook_form_for(:my_object, :url => { :action => ''upload_photo'', :id => params[:id] }, :html => {
2006 Jan 06
2
Re: Some advice on DB modeling
I have more or less the same problem. I''m trying to build a system where users can enter their friends. But the solutions seems not to work for me. I used same sql: CREATE TABLE `friends` ( `user_id` int(11) NOT NULL default ''0'', `friend_id` int(11) NOT NULL default ''0'', KEY `user_id` (`user_id`), KEY `friend_id` (`friend_id`),
2005 Nov 03
0
AR model and virtual attributes
i have a need to create a ''virtual'' attribute. Is the following possible? class User < ActiveRecord::Base # user things are owned by user at his selected location has_many :owned_things, :class_name => "Thing", :conditions => ''user_id = #{id} and location_id = #{location_id}'' attr_accessor :location_id end class AccountController <
2006 Mar 28
1
Model attributes that are not backed by persistent storage
I have a model object that I would like to add an attribute to. It''s an array of other objects. If I do attr_accessor :local_image_tags should I then be able to assign to object.local_image_tags or read from object.local_image_tags without incident? Is ActiveRecord going to assume that there is a table behind these guys? If so, how do I indicate that these attributes are not
2007 Jun 23
4
inverse examples? (should fail)
The new "pending" example feature reminds me of a feature I''ve been bouncing around in my head, to aid in refactoring. Often, when I''m changing existing behaviour, I know that certain aspects of the old behaviour should change. Imagine changing the "it" method to perhaps "not" or "old" or "removed"... The behaviour would be to
2011 Oct 25
7
additional model attributes
Hi, i have a "place" model with 2 columns (id, name). I''m calling an external api which gives me data to create a new place object. I would like to add the address from the external place to the place object and render it as a json result, without storing it in the database. i don''t get any errors, but the address never shows up within the json output. i''ve
2005 Oct 16
13
More than one parameter with link_to_remote
Hi all, I''m trying to pass more than one parameters using link_to_remote, but I''m getting a behaviour that seems quite strange to me. Here''s the code: link_to_remote ''some text'', :update => ''form'', :method => ''get'', :url => { :action =>
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: >>
2006 Jul 23
4
Anything like with_scope for ActionController?
There are areas of my application that "want" to use a url structure like domain/<human_readable_param>/<Module>/<Controller>/<Action>/<Id> Please note that the human readable parameter I need to inject is NOT related to the <id> being used by the action/controller pair. It''s identifying a container object whose contains are operated
2010 Jul 08
3
Testing equality
Hello How can I test equality with two objects when they include some attribute that is BigDecimal? if I make something like this: it "should ...whatever" do obj = Factory.create(:my_object) ... MyObject.first.should == obj end. FAILS This fails because the object expected is different from the object gotten, and the only difference are the BigDecimal attributes, that are
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
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
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:
2005 Oct 14
1
Diff between attr_accessible and attr_accessor
I''m going though the paper back edition of agile development with Rails. On page #128 I encountered following lines of code: attr_accessor :password attr_accessible :name,:password What''s the difference between attr_accessor and attr_accessible? -=- Neeraj _______________________________________________ Rails mailing list
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 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
2006 Jan 04
2
collection_select with array as source
I would like to use the collection_select with a simply array as the source of the collection. My array looks like this: STATES = ["Alabama", "Alaska", "Texas"] and it is stored in my environment.rb I can''t figure out the syntax for the collection_select in this situation... collection_select("my_object", "state", what goes here??? ) I