Apologies first, because I need to ramp up on Ruby and coding Ruby in Rails, however it''s my 3rd day with this beast :) so I''m asking : When I added protected methods to the model before it was like: protected method.................... end Would this be a valid way to write a protected method as well ?: attr_protected :column1, :column2 Perhaps this particular call is already protected inherent to the call, yet do I need to surround it with "protected" and "end" ? TIA Stuart -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060607/eb099dcb/attachment.html
On 7-Jun-06, at 7:44 AM, Dark Ambient wrote:> Apologies first, because I need to ramp up on Ruby and coding Ruby > in Rails, however it''s my 3rd day with this beast :) so I''m asking : > > When I added protected methods to the model before it was like: > > protected > method.................... > end > > Would this be a valid way to write a protected method as well ?: > > attr_protected :column1, :column2 > >''protected :foo'' is not the same as ''attr_protected :foo'' ''protected'' affects the ability of other objects to call the ''foo'' method on your object. ''attr_protected'' affects the params that are considered acceptable for mass assignment (new({}), attributes={}, update_attributes({})) for an ActiveRecord::Base subclass (i.e. your models). For example: class Foo < ActiveRecord::Base protected :column1end x = Foo.new x.column1 = "hello" # disallowed x.attributes = {:column1 => ''hello''} # allowed Foo.new(:column1 => ''hello'') # allowed class Bar < ActiveRecord::Base attr_protected :column1end x = Bar.new(:column1 => ''hello'') # column1 parameter silently discarded x.attributes = {:column1 => ''hello''} # silently discarded here too x.column1 = ''hello'' # allowed Regards, Trevor> Perhaps this particular call is already protected inherent to the > call, yet do I need to > > surround it with "protected" and "end" ? > > TIA > Stuart > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Trevor, Thanks for the very detailed explanation. I don''t think it''s totally sunk in but I"ll continue to re-read and look up more info on protected methods. Probably best if I combine learning Rails with Ruby as well. Stuart On 6/7/06, Trevor Squires <trevor@protocool.com> wrote:> > > On 7-Jun-06, at 7:44 AM, Dark Ambient wrote: > > > Apologies first, because I need to ramp up on Ruby and coding Ruby > > in Rails, however it''s my 3rd day with this beast :) so I''m asking : > > > > When I added protected methods to the model before it was like: > > > > protected > > method.................... > > end > > > > Would this be a valid way to write a protected method as well ?: > > > > attr_protected :column1, :column2 > > > > > ''protected :foo'' is not the same as ''attr_protected :foo'' > > ''protected'' affects the ability of other objects to call the ''foo'' > method on your object. > > ''attr_protected'' affects the params that are considered acceptable > for mass assignment (new({}), attributes={}, update_attributes({})) > for an ActiveRecord::Base subclass (i.e. your models). > > For example: > > class Foo < ActiveRecord::Base > protected :column1> end > > x = Foo.new > x.column1 = "hello" # disallowed > x.attributes = {:column1 => ''hello''} # allowed > Foo.new(:column1 => ''hello'') # allowed > > class Bar < ActiveRecord::Base > attr_protected :column1> end > > x = Bar.new(:column1 => ''hello'') # column1 parameter silently discarded > x.attributes = {:column1 => ''hello''} # silently discarded here too > x.column1 = ''hello'' # allowed > > Regards, > Trevor > > > Perhaps this particular call is already protected inherent to the > > call, yet do I need to > > > > surround it with "protected" and "end" ? > > > > TIA > > Stuart > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060607/690e8e64/attachment-0001.html
If you don''t have it, get Agile Web Development with Rails and work through that. That''s a good way of getting going pretty quickly. When I first started (only a few weeks ago), I found it just fine to learn rails and pick up the ruby as I went along. -Nathan On 07/06/06, Dark Ambient <sambient@gmail.com> wrote:> Trevor, > Thanks for the very detailed explanation. I don''t think it''s totally sunk > in but I"ll continue to re-read and look up more info on protected methods. > Probably best if I combine learning Rails with Ruby as well. > > Stuart > > > On 6/7/06, Trevor Squires <trevor@protocool.com> wrote: > > > > On 7-Jun-06, at 7:44 AM, Dark Ambient wrote: > > > > > Apologies first, because I need to ramp up on Ruby and coding Ruby > > > in Rails, however it''s my 3rd day with this beast :) so I''m asking : > > > > > > When I added protected methods to the model before it was like: > > > > > > protected > > > method.................... > > > end > > > > > > Would this be a valid way to write a protected method as well ?: > > > > > > attr_protected :column1, :column2 > > > > > > > > ''protected :foo'' is not the same as ''attr_protected :foo'' > > > > ''protected'' affects the ability of other objects to call the ''foo'' > > method on your object. > > > > ''attr_protected'' affects the params that are considered acceptable > > for mass assignment (new({}), attributes={}, update_attributes({})) > > for an ActiveRecord::Base subclass (i.e. your models). > > > > For example: > > > > class Foo < ActiveRecord::Base > > protected :column1> > end > > > > x = Foo.new > > x.column1 = "hello" # disallowed > > x.attributes = {:column1 => ''hello''} # allowed > > Foo.new(:column1 => ''hello'') # allowed > > > > class Bar < ActiveRecord::Base > > attr_protected :column1> > end > > > > x = Bar.new(:column1 => ''hello'') # column1 parameter silently discarded > > x.attributes = {:column1 => ''hello''} # silently discarded here too > > x.column1 = ''hello'' # allowed > > > > Regards, > > Trevor > > > > > Perhaps this particular call is already protected inherent to the > > > call, yet do I need to > > > > > > surround it with "protected" and "end" ? > > > > > > TIA > > > Stuart > > > > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
Nathan Thanks for the suggestion - I was actually considering asking. Reason being that I have Agile Web Dev (2nd edition now) and after reading the prelimanary overview of rails, went ahead and started on the depot. However it seemed to me (and it maybe premature of me having not read through the entire book) that a good Ruby compliment would be beneficial. So I picked up the Manning book, Ruby for Rails by David Black. The title makes the contents self-descriptive. Curious as to what others might think because 2 books at this point might be overload for me, yet I don''t want to plow through rails without a better understanding of what I need to know in Ruby. I read somewhere recently that people come to rails without understanding ruby and develop by copying code without really understanding what''s being written. This is something I would prefer to avoid (unless it paid the rent :)). Stuart On 6/7/06, njmacinnes@gmail.com <njmacinnes@gmail.com> wrote:> > If you don''t have it, get Agile Web Development with Rails and work > through that. That''s a good way of getting going pretty quickly. When > I first started (only a few weeks ago), I found it just fine to learn > rails and pick up the ruby as I went along. > -Nathan > > On 07/06/06, Dark Ambient <sambient@gmail.com> wrote: > > Trevor, > > Thanks for the very detailed explanation. I don''t think it''s totally > sunk > > in but I"ll continue to re-read and look up more info on protected > methods. > > Probably best if I combine learning Rails with Ruby as well. > > > > Stuart > > > > > > On 6/7/06, Trevor Squires <trevor@protocool.com> wrote: > > > > > > On 7-Jun-06, at 7:44 AM, Dark Ambient wrote: > > > > > > > Apologies first, because I need to ramp up on Ruby and coding Ruby > > > > in Rails, however it''s my 3rd day with this beast :) so I''m asking : > > > > > > > > When I added protected methods to the model before it was like: > > > > > > > > protected > > > > method.................... > > > > end > > > > > > > > Would this be a valid way to write a protected method as well ?: > > > > > > > > attr_protected :column1, :column2 > > > > > > > > > > > ''protected :foo'' is not the same as ''attr_protected :foo'' > > > > > > ''protected'' affects the ability of other objects to call the ''foo'' > > > method on your object. > > > > > > ''attr_protected'' affects the params that are considered acceptable > > > for mass assignment (new({}), attributes={}, update_attributes({})) > > > for an ActiveRecord::Base subclass (i.e. your models). > > > > > > For example: > > > > > > class Foo < ActiveRecord::Base > > > protected :column1> > > end > > > > > > x = Foo.new > > > x.column1 = "hello" # disallowed > > > x.attributes = {:column1 => ''hello''} # allowed > > > Foo.new(:column1 => ''hello'') # allowed > > > > > > class Bar < ActiveRecord::Base > > > attr_protected :column1> > > end > > > > > > x = Bar.new(:column1 => ''hello'') # column1 parameter silently > discarded > > > x.attributes = {:column1 => ''hello''} # silently discarded here too > > > x.column1 = ''hello'' # allowed > > > > > > Regards, > > > Trevor > > > > > > > Perhaps this particular call is already protected inherent to the > > > > call, yet do I need to > > > > > > > > surround it with "protected" and "end" ? > > > > > > > > TIA > > > > Stuart > > > > > > > > > > > > _______________________________________________ > > > > Rails mailing list > > > > Rails@lists.rubyonrails.org > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060607/eeefa81f/attachment-0001.html