search for: attr_read

Displaying 20 results from an estimated 168 matches for "attr_read".

Did you mean: attr_reader
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 -- Posted via http://www.ruby-forum.com/. -...
2006 Mar 13
4
undefined method `validates_presence_of'' for #<ProductsContr
Hi, I am trying to use method `validates_presence_of'' for validating my input fields on form . I m using it in my action class as follows:- ======================= validates_presence_of(params[:product][:quantity]) ====================== But when I am running my application i m getting error like:- ========================= undefined method `validates_presence_of'' for
2008 Feb 16
2
nil error?
...to just increment a variable and I think I''m missing some basic concept (this is RoR 2.0.2 btw) So have a "players" table with several variables, including one called "odds". I''m using the basic scaffold generator for the CRUD stuff, but in my model I have: attr_reader :odds def initialize(odds) @odds = odds end def winGame @odds += 1 end (note: attr_reader makes the odds in the index list disappear from view.) in the controller I have: def winner player = Player.find(params[:id]) player.winGame respond_to do |format| f...
2006 Mar 19
4
Trouble with composed_of
I''m trying to use composed_of within my model. I have a field in my database named ''card1'', which is simply a string. I have this in my model class Player < ActiveRecord::Base composed_of :card1, :class_name => ''Card'' end class Card attr_reader :value, :suit def initialize(s) @value = s[0].chr @suit = s[1].chr end end The accessor method works fine..in my fixture I have a Player created with card1: As, and I can do players(:first).card1.suit # => ''s'' But I can''t assign it: players(:first).c...
2006 Apr 12
1
Dynamically updating list
...class ListnoajaxController < ApplicationController def index @items = Item.find_recent end def add_item item = Item.new(params[:item_body]) render(:partial => "item", :object => item) end def item end end 2)the code for item class in app/model class Item < ActiveRecord::Base attr_reader :body attr_reader :posted_on FAKE_DATABASE = [] def initialize(body) @body = body @posted_on = Time.now FAKE_DATABASE.unshift(self) end def self.find_recent FAKE_DATABASE end # Populate initial items new("Feed cat") new("Wash car") new("Sell start-up to Google") end...
2006 Jan 28
4
Randomised variables from sql
I''ve spent some time converting my website from php to RoR, and so far, I''m loving every bit of Rails. However, I''ve stumbled across a problem. On my old page, I''ve had a random quote display at a specific location, and I''d like to replicate this with RoR. Basically, I thought I would be able to add all quotes into a specific table in the database,
2006 Jul 24
1
Newbie error: undefined local variable or method
...thod...??? Code included below for reference. The code starts with the Store controller: def add_to_cart @cart = find_cart @product = Product.find(params[:id]) @cart.add_product(@product) end The add_product method is in the Cart model: class Cart include Reloadable attr_reader :items def initialize @items = [] end def add_product(product) existing_product = @items.find {|item| item.product == product} if existing_product existing_product.increment_quantity else @items << CartItem.new(product) end end end The cart_item.quantity and cart_it...
2007 Aug 30
3
Rails - depot application
...;" this is display_cart.rhtml line_item.rb has: "class LineItem < ActiveRecord::Base belongs_to :product def self.for_product(product) item = self.new item.quantity = 1 item.product = product item.unit_price = product.price end end " cart.rb has: "class Cart attr_reader :items attr_reader :total_price def initialize @items = [] @total_price = 0.0 end def add_product(product) @items << LineItem.for_product(product) @total_price += product.price end end " It looks like product = item.product in display_cart.rhtml is pulling out a d...
2008 Jan 26
0
JRuby version of win32-api - initial try
...GetProcAddress = KERNEL32.getFunction(''GetProcAddress'') FormatMessageA = KERNEL32.getFunction(''FormatMessageA'') LocalFree = KERNEL32.getFunction(''LocalFree'') public VERSION = ''1.0.6'' attr_reader :function_name attr_reader :prototype attr_reader :return_type attr_reader :dll_name def initialize(function, prototype=''V'', return_type=''L'', dll=''kernel32'') # Convert a prototype string to an array of c...
2008 Jun 04
2
Win32-ole start
...Windows::Error include Windows::COM include Windows::COM::Automation include Windows::Unicode # Error raised if any of the OLE related methods fail. class Error < StandardError; end # The name of the OLE automation server specified in the constructor. attr_reader :server # The host the OLE automation object was created on. attr_reader :host # Did I declare these properly? # http://tinyurl.com/3z8z4h IID_IUnknown = [0,0,0,192,0,0,0,0,0,0,70].pack(''ISSCCCCCCCC'') IID_IDispatch = [132096,0,0,192,0...
2006 Apr 06
0
Class definition OK?
Something''s not working, and I just want to make sure that my class is not to blame and that I''ve got how it works straight in my head: The attr_reader parts make those :something (hash values, i think) accessible as @class.something attributes outside of the class. So, once I find the right session in the controller, I can access those values as @session.something. Right? For some reason I''m just getting zero for @question_total an...
2006 Mar 31
1
dumb question: what is attr_xxxx
i''m very new to the rails scene and am seeing lines of code like attr_reader, attr_writer, attr_accessor, etc... and have no idea what they do. reading the section in the book i''m reading that explains the previous block of code says nothing about it really. -- Posted via http://www.ruby-forum.com/.
2007 May 24
2
Missing RspecScaffoldGenerator
...=========== --- rspec_scaffold_generator.rb (revision 2022) +++ rspec_scaffold_generator.rb (working copy) @@ -1,4 +1,4 @@ -class RspecResourceGenerator < Rails::Generator::NamedBase +class RspecScaffoldGenerator < Rails::Generator::NamedBase default_options :skip_migration => false attr_reader :controller_name,
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
2006 Aug 04
6
Errors ... errors and errors.
...e cart end private def find_cart unless session[:cart] #if there is no cart in sesssion add one session[:cart] = Cart.new #add a new one end session[:cart] #return existing or new cart end end [CODE] Also here is the cart.rb [CODE] class Cart include Reloadable attr_reader :items def initialize @items = [] end def add_product(product) existing_product = @items.find {|item| item.product == product} if existing_product existing_product.increment_quantity else @items << Cart.new(product) end end end [CODE] And here is t...
2006 Jun 24
4
setting attribute in constructor, .NEW works but not .CREATE
I have table "decks" with three fields: "id", "created_at" and "cards" which is a 264-character string field. I have modified the model with a constructor, as follows: class Deck < ActiveRecord::Base attr_reader :cards def initialize @cards = "12345" end end If I call Deck.new from my controller, I get no errors and an object with the "cards" attribute set appropriately to "12345". This object can be saved without error by calling the .save method. However, if I call...
2006 May 26
9
What syntax is this? belongs_to :Person
...cond edition I don''t see anything like the syntax you see people using in rails code. Specifically when you see. belongs_to :Person has_many :Phones etc these are methods on ActiveRecord right? Why is this invocation syntax never described in the Pick Axe book? I do see things like attr_reader :some_attribute etc but you don''t see it in the context of invoking a method on your ancestor. Can somebody cite me where this is described in the Pick Axe book?
2007 Jan 25
4
How to change the menu depending on the controller/method?
...ave a database with menu_groups (corresponding to controllers) and menu_elements(corresponding to methods). Each menu_element belongs to one menu_group. I created a class Menu where I get all the menu_groups and menu_elements, and where I have the active controller and method. " class Menu attr_reader :menu_groups attr_reader :menu_group_active attr_reader :menu_elements attr_reader :menu_element_active def initialize current_url_elements=request_uri().split("/") @menu_groups << MenuGroup.find(:name,:order => "id") @menu_group_active = controll...
2006 Jan 15
4
form inputs resetting on sumbit
I searched for forum for something about this but couldn''t find anything. For example I have this in my view: (you enter start/end dates from dropdowns, pick a category and a report is generated.) <%= start_form_tag :action => ''display_report'' %> From: <%= date_select ''report'', ''date1'' %> <br /> To: <%=
2006 Mar 15
7
rails on OS X 10.3.9 not working
Hello, I''ve installed Ruby 1.8.4 via Darwinports, installed gem 0.8.11 too and then installed Rails via gem. I''m using OS X 10.3.9. When I now type rails in the terminal, the following lines appear: # rails /opt/local/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/ active_support/values/time_zone.rb:12: undefined method `attr_reamer'' for TimeZone:Class