search for: attr_writer

Displaying 20 results from an estimated 29 matches for "attr_writer".

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...
2006 Jan 09
1
Saving an upload
...m_id integer NOT NULL, picture_id integer NOT NULL, "position" integer NOT NULL, primary key (film_id, picture_id) ); Here''s the Ruby: film.rb: class Film < ActiveRecord::Base has_and_belongs_to_many :pictures, :join_table => "films_pictures" attr_writer :uploaded_files attr_reader :uploaded_files validates_presence_of :name, :description, :has_subtitles, :is_censored end picture.rb: class Picture < ActiveRecord::Base has_many :films has_many :comics acts_as_list :picture_id attr_writer :parent_id attr_writer :type validate...
2007 Sep 03
7
relationing has_many, belongs_to
Hello, i want to know if i am relationing fine, because i am having problems,i have 2 models, one for members and other to relate some members to this: class Member < ActiveRecord::Base has_many :matrix, :foreign_key=>:parent end class Matrix < ActiveRecord::Base set_table_name :matrix set_primary_key :userid belongs_to :member, :foreign_key=>:userid acts_as_tree
2006 Jan 12
1
A really newbie question
...mail) which would either update the existing record if a match on either alias or email is found, or create a new record if no matches are found. But despite many tries it just doesn''t work. Did I set the accessor parameters correctly? Thanks. -- class User < ActiveRecord::Base attr_writer :alias, :email def self.newuser?(p_alias, p_email) user = find_first(["alias = ? OR email = ?", p_alias, p_email]) if user.nil? return true else return false end end def self.addupdate(p_alias, p_email) t_user = find_first(["alias = ? OR email...
2006 Feb 07
0
Rendering objects directly via <%= render @some_object %>
...render method # The options parameter, which contains the original options hash, # could optionally be uesd to when generating the hash. # def renject_render_options( options = {} ) # Generate the wished for hash return { :partial => @partial, :locals = {:foo => @foo, :baa => @baa }} end attr_writer :partial attr_writer :foo attr_writer :baa end @some_object = SomeClass @some_object.partial = ''Partial'' @some_object.foo = ''Foo'' @some_object.baa = ''Baa'' ----------------- Rendering @some_object via <%= render @some_object %> corresp...
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 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 Jan 09
1
assert_redirected_to not working as expected
...:password => "gomer", :password_confirmation => "gomer") end ... def test_successful_signup gooddog = enter_site(:gooddog) gooddog.signs_up_successfully end ... private module BrowsingTestDSL include ERB::Util attr_writer :name ... def signs_up_successfully post_signup("gooddog", "gooddog-plI9Zfxs2xb6V6G2DxALlg@public.gmane.org", "gooddog", "gooddog") assert_redirected_to :controller => "home", :action => "welcome" end ......
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
2007 Mar 21
2
A real puzzler: attr_accessor / create incompatibility?
...''t seem to be used by the internal persistence logic. I have tested this as follows: If I remove the attr_accessor line from the State definition, it all works just fine. In fact, if I replace the attr_accessor with an attr_reader, that works fine. However, if I use an attr_accessor or an attr_writer statement, I see this rather unexpected behavior. Perhaps this is expected behavior and I am missing something here? Or perhaps there is something I have in my environment that is causing this? Any help here would be appreciated! --~--~---------~--~----~------------~-------~--~----~ You receive...
2008 Mar 04
4
Named collection forward fetching
...i do current_user.best_friend everything works great, I can pull up the user''s name as an example. My user model has a one-to-many relationship with interests. If I do current_user.best_friend.interests however it gives a no method error. Does this have anything to do with attr_reader / attr_writer? Thanks, GP -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocF...
2006 Jan 11
6
How to display the error messages from the controller
I have a wizard which consists of two pages. To keep it simple let''s say that the first page asks the user to select a state from the drop down menu. In case the user doesn''t select any state, an error message needs to be displayed. Ideally I would like to do something like this. def new selected_value = params[:addevent][:state_id] if selected_value == "-1"
2006 Aug 14
1
What fields_for really for?
...e belongs_to :district validates_numericality_of :region_id, :only_integer => true end In edit.rhtml for SuburbController I need to specify region_id. There is no region_id in suburb model so first I added these lines to it: ... class Suburb < ActiveRecord::Base belongs_to :district attr_writer :region_id def region_id district.region_id if district end def region_id_before_type_cast region_id end validates_numericality_of :region_id, :only_integer => true end ... Its all working now but it looks messy! And I need this functionality in another few places. Obviously...
2006 Jan 11
1
logger in my classes
Hi, I wrote a class which is not an AR extension, nor a controller. I''d like to use logger.* methods there too. My class is in lib/ dir. I include it in environment.rb with the line require ''lib/localization'' just after the line require File.join(File.dirname(__FILE__), ''boot'') I tried many ways to reuse the logger class. The cleaner way seemed to
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
2013 Jun 25
0
attr :location_string
Hi, I have come across attr :location_string inside a class definition in Rails application. class Web < class Params attr :location_string def .... end .... end I know how attr_accessor, attr_reader or attr_writer works. But I don''t have any idea on attr in Rails. Can you kindly explain what it does? Thanks, Christopher -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe fro...
2006 Sep 05
5
cattr_accessor
Hi, i''ve been playing with ror for a little over two months now, and was wondering wether someone could explain to me what was cattr_accessor and if it is still in use. . . i looked up in api.rubyonrails.com and coulnd''t find any documentation... is it a useful/worth learning method? what do u use it for? -- Posted via http://www.ruby-forum.com/.
2006 Apr 03
7
Getters and setters problem?
Hi list, first evening of playing with rails, so please forgive me if I ask something stupid. ;-) I created a User model and tried to use ActiveRecord callbacks to convert the password to sha1 just before saving it. For some reason postgresql gives me a error because 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
2006 Aug 07
3
Acts_as_taggable / Rails Recipes bug?
I''m following the acts_as_taggable chapter from the Rails Recipes book. I want my view form to have a text_field that correlates to an attribute in the Model that accepts a string of space delimited tags. The book uses tag-_list, but from what I can tell this attribute can''t be written to. I''ve added this to the plugin code itself - am I missing something, is there a
2006 Jun 16
2
News posting system without a database
I need to create a news posting system without the use of a database. I''m going to create a file for each news post and have the view post each file in a specific directory as HTML. The newspost will contain: 1. A title. 2. A date. 3. The body. In the text file, I want line 1 to be the title, line 2 to be the date, and everything from line 3 on down to the be the body. What method