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: 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 rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Mar-07 16:53 UTC
Re: difference between attr_accessor and attr_accessible?
On Mar 7, 4:45 pm, Gaba Luschi <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > > What''s the difference between attr_accessor and attr_accessible? >They''re completely unrelated. attr_accessor is a pure ruby method and creates a setter & getter method for an instance variable. attr_accessible (and its counterpart attr_protected) are railsisms and are there to control which properties of an object a user can change through mass assignment Fred> 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 viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Gaba Luschi
2011-Mar-07 17:02 UTC
Re: difference between attr_accessor and attr_accessible?
Thanks - what''s mass assignment? Assigning attributes to an object? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Tim Shaffer
2011-Mar-07 17:35 UTC
Re: difference between attr_accessor and attr_accessible?
This is mass assignment: User.new(params[:user]) Basically assigning all the attributes to the an instance based on the params[:user] hash. -- 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 rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Seemingly Similar Threads
- attr_accessible & attr_accessor - what's the difference?
- attr_accessor vs attr_accessible
- Diff between attr_accessible and attr_accessor
- attr_accessible on some properties + attr_protected on others makes class 'open-by-default'
- When adding a record in console, a parameter comes in as null even when I set it