search for: attr_accessor

Displaying 20 results from an estimated 279 matches for "attr_accessor".

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...
2006 Jan 06
2
Re: Some advice on DB modeling
...9;, :foreign_key => ''friend_id'' has_and_belongs_to_many :friends_of, :join_table => ''friends'', :class_name => ''User'', :foreign_key => ''user_id'', :association_foreign_key => ''friend_id'' attr_accessor :new_password attr_accessor :friends attr_accessor :friends_of ... end But when I use user.friends or user.friends_of they always return nil even after I entered some data in the db manually. There are no errors in the logfile... Any ideas? thanks Frank
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 G...
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....
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 Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo...
2009 Nov 27
2
attr_accessible & attr_accessor - what's the difference?
i''m still new to rails and working on digesting everything i come across. recently i came across these two. what is the difference between attr_accessor and attr_accessible? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrail...
2009 Sep 09
4
undefined method `attr_accessor' for #&lt;CustomersControl
pleas help -- Posted via http://www.ruby-forum.com/.
2006 Aug 12
10
adding extra variable to a class, how to access it?
somple question here but pretty confusing on my side. i have a model towns that is mapped to my towns table. can i add an extra variable to the class and access it in my view? basicall what i am trying to do is return a list of towns, and next to each town, display a total number of what i have in each town. ive tried both attr_reader and @total but no avail. here is my view <% for
2008 Jun 24
1
cache issue with attr_accessor field
Hi, I''ve got a model with the following attribute added: attr_accessor :level which does not exist in the database. After putting instances of this model in the cache (using Rails.cache.fetch(''foo'') { Category.all } ), when I retrieve it back from the cache, then trying to access .level gives: undefined method `level'' for #<Category:0...
2007 Jan 24
2
attr_accessor vs attr_accessible
Please guide me how to use those two methods. I can''t differentiate them. I was doing something on my model and I have put one field in the attr_accessible method. After that when I try to run the app the app always says my other fields are blank, but they''re all filled up. What''s wrong with it? Thanks --~--~---------~--~----~------------~-------~--~----~ You received
2011 Jan 08
4
Help How to create DSL for conditional validations
...onal validations valid_with_cond :bypass_validation do if self.addresses > 3 errors[:base] << "Can not have more than 3 addresses". end end By this I wanted to create array of method and call them all in custom validation method. this above code I wanted to do attr_accessor :bypass_validation def svalid_cond unless bypass_validation if self.addresses > 3 errors[:base] << "Can not have more than 3 addresses". end end end This way I want in new and edit form I can ask user to click :bypass_validation a...
2006 Feb 05
3
attr_accessor help understanding
i''m having trouble understanding the attr_accessor and attr_accessible syntax in models. I''m workink through the Agile book and even a look at the ruby doc does not really help to clarify. Thanks aftershock -- Posted via http://www.ruby-forum.com/.
2007 Dec 04
10
Unexpected message on :attr_accessor
This may be a dumb noob issue, but I haven''t found any answers while seaching the forum-- I have a controller method def edit @user = User.find params[:id] @user.password_confirmation = @user.password end The User class has an "attr_accessor :password_confirmation" definition (so "password_confirmation" doesn''t exist in the users table). My spec has the following it "should find User on GET to users/edit/:id" do User.should_receive(:find).and_return(@user) @user.should_receive(:password_conf...
2006 May 09
1
Session mgmt. bug - ActiveRecord & MemoryStore session store
...ants 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 descends from ActiveRecord::Base 2) Add an attr_accessor for an attribute test_attr to model object X 3) Create one action in your controller that creates a new X sets the test_attr value on X to be something stores X in the session 4) Create another action in your controller that simply attempts to access the test_attr attribute on the session co...
2007 Apr 28
3
Learning ruby question
...ain the difference between the following 2 programs. They both return the same output "aaaaaaaa", but I''m just not sure about self in #1. Is self.day and self.title referring to and setting class variables or are they instance variables? Thanks in advance. # 1. class Session attr_accessor :day, :title def initialize() self.day = "aaaaaaaa" self.title = "bbbbb" end end s=Session.new puts s.day ################### # 2. class Session attr_accessor :day, :title def initialize() @day = "aaaaaaaa" @title = "bbbbb" e...
2008 Sep 06
6
Configuring custom library
Hi, I''ve added a custom library called lib\AccountSystem like so: "module AccountSystem SINGLE = 1 MULTIPLE = 2 class << self attr_accessor :account_system_type end end" Now I wanna configure AccountSystem.account_system_type=AccountSystem::SINGLE in one app. I used an initializer: config/initializers/account_initialization.rb where I put this line in. I included my AccountSystem in the ApplicationController. So now I'...
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 :username, :size => 40%> <%= form.text_field "person.first_name", :size => 40%> ????? doesn''...
2007 Sep 23
9
Code reviews: my dumb use of acts_as_commentable (newbie)
...gt; <%= f.text_field :new_comment_body, :size => 200 %> </p> <%= submit_tag "Save Comment", :class => "submit" %> <% end %> </fieldset> My review.rb model has: acts_as_commentable # yeah, this seems fine attr_accessor :new_comment_title # do I really need this?? attr_accessor :new_comment_body # ditto attr_accessor :review_id # c''mon, this can''t be necessary! and my controller has def show_review @review = Review.find(params[:id]) # fine @review.review_id = @review.id...
2006 Feb 15
8
Agile book - getting confusing error
...`add_user'' ... Request Parameters: {"user"=>{"name"=>"Craig White", "login"=>"craig", "password"=>"test"}} OK... My user.rb includes... require "digest/sha1" class User < ActiveRecord::Base attr_accessor :password attr_accessible :login, :password, :name def before_create self.hashed_password = User.hash_password(self.password) end private def self.hash_password(password) Digest::SHA1.hexdigest(password) end end Where am I going wrong? Craig
2006 Apr 03
7
Getters and setters problem?
...e the given password is null. To test even further I tried to change :login too, same error happens, :login is empty too. I am sure I am missing something really obvious, but I don''t see it yet. Here is the model code: require "digest/sha1" class User < ActiveRecord::Base attr_accessor :password, :login attr_accessible :password, :name, :login, :email validates_confirmation_of :password validates_presence_of :name, :login, :password, :email validates_uniqueness_of :login def before_create self.password=User.hash_password(self.password) self.login="blaat&qu...