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 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 -~----------~----~----~----~------~----~------~--~---
Hi James, attr_accessible is used to identify attributes that are accessible by your controller methods. This is to protect your models from being written to by malicious users posting values that they shouldn''t be into your create and update methods. All of your fields are blank except the one that you specified to be accessible because rails is doing it''s job :) attr_accessible will only allow access to the attributes that you specify, denying the rest. attr_protected will deny access to the attributes that you specify, allowing the rest, and specifying neither in your model will allow access to all attributes. attr_accessor is an easy way to create read and write accessors in your class. attr_accessor :myvar replaces the following. def myvar @myvar end def myvar=(myvar) @myvar=myvar end hope that helps. Jason On Wed, 24 Jan 2007 03:03:52 -0000 "james_027" <cai.haibin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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 > > > >-- Jason Stewart | Tel: 616-532-2300 Systems Administrator/ | Fax: 616-532-3461 Programmer | Email: jstewart-hPVRf1w6JnE@public.gmane.org Right to Life of Michigan | Web: http://www.rtl.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Jason, That was really a well explained. But I find some things that works not according to what you''ve said. I have a model with 6 attributes. And in my controller I only access the password attribute. So I code attr_accessible :password. All of the sudden the validates method doesn''t work as it should be. Even if the fields where filled up correctly the validates method keeps on triggering, until I put all my attributes to attr_accessible. But everything was working well when I haven''t code attr_accessible :password. On Jan 24, 9:47 pm, Jason Stewart <jstew...-hPVRf1w6JnE@public.gmane.org> wrote:> Hi James, > > attr_accessible is used to identify attributes that are accessible by > your controller methods. This is to protect your models from being > written to by malicious users posting values that they shouldn''t be > into your create and update methods. All of your fields are blank > except the one that you specified to be accessible because rails is > doing it''s job :) > > attr_accessible will only allow access to the attributes that you > specify, denying the rest. attr_protected will deny access to the > attributes that you specify, allowing the rest, and specifying neither > in your model will allow access to all attributes. > > attr_accessor is an easy way to create read and write accessors in your > class. attr_accessor :myvar replaces the following. > > def myvar > @myvar > end > > def myvar=(myvar) > @myvar=myvar > end > > hope that helps. > > Jason > > On Wed, 24 Jan 2007 03:03:52 -0000 > > "james_027" <cai.hai...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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-- > Jason Stewart | Tel: 616-532-2300 > Systems Administrator/ | Fax: 616-532-3461 > Programmer | Email: jstew...-hPVRf1w6JnE@public.gmane.org > Right to Life of Michigan | Web:http://www.rtl.org--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Possibly Parallel Threads
- difference between attr_accessor and attr_accessible?
- attr_accessible & attr_accessor - what's the difference?
- Diff between attr_accessible and attr_accessor
- undefined method `attr_accessor' for #<CustomersControl
- How to protect attributes from being updated?