Folks, newbie here and I have a quick question about attr_accessor. I''m developing a very basic CMS and I set up a simple class for a user. In that class I use attr_accessor to set up the read, write, etc methods. Then in a very basic a controller I create an instance variable @post = post(:all) and I then render the title of the post along with the user name in the view. Strangely, the title appears, but the user name doesn''t. BUT, if I remove the attr_accessor in the model the user name appears just fine. I thought that attr_accessor didn''t do that and that methods like attr_accessible or attr_protected should be used instead to restrict access to the method. What''s happening here? Do miss understand how attr_accessor works? TIA! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 6 Nov 2007, at 07:04, Pat wrote:> > > What''s happening here? Do miss understand how attr_accessor works?I suspect the attr_accessor is overwriting the accessor methods that rails creates for your database attributes. attr_protected etc... are only for dealing with mass assignment (ie Post.new(params[:post]))) Fred --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 11/6/07, Pat <mill226-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Folks, newbie here and I have a quick question about attr_accessor. > > I''m developing a very basic CMS and I set up a simple class for a > user. In that class I use attr_accessor to set up the read, write, > etc methods. > > Then in a very basic a controller I create an instance variable @post > = post(:all) and I then render the title of the post along with the > user name in the view. Strangely, the title appears, but the user > name doesn''t. BUT, if I remove the attr_accessor in the model the > user name appears just fine. I thought that attr_accessor didn''t do > that and that methods like attr_accessible or attr_protected should be > used instead to restrict access to the method.attr_accessor is a Ruby (not Rails) thing that sets up "getter/setter" methods for an instance variable. You shouldn''t use attr_accessor for the columns in an AR model; AR creates getter/setter methods for you. What are you trying to accomplish with attr_accessor here? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---