I feel like I''m missing something rather important in both circumstances, but I can''t seem to figure either out: 1) I have a model named TestCase - class TestCase < ActiveRecord::Base belongs_to :test_suite scope :queued, lambda { where("test_cases.suite_id IS NOT NULL") } scope :assigned_to, lambda { |sid| where(:suite_id => sid) } end The controller can interact with it perfectly fine. When trying to display information from it in either the view or via the view helper such as TestCase.all, I get a NoMethodError (undefined method `all''.) If I call it with ::TestCase.all, that works. I had a theory that it has something to do with the fact that it''s associated to another model (belongs_to ...), I just can''t find anything to confirm that or tell me why that happens. 2) On another project I have yet another model named Artwork. Again, it has associations (belongs_to). In this case, I can access it just fine in the view, and all the methods within it work fine for the controller except if I try to do dynamic method calls. In this case I have a simple toggle for - @artwork = Artwork.find(params[:id]) value = params[:value].to_sym @artwork.update_attributes(value => !@artwork.method(value).call) That gives me a NoMethodError. However, if I add - if @artwork.respond_to?(value) - then it works as expected. Again, I can''t figure out why. Both items I get working using the mentioned methods, but again, I feel like I''m really missing something important 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-/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.
On Nov 22, 10:37 pm, Aedorn Varanis <aed...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I feel like I''m missing something rather important in both > circumstances, but I can''t seem to figure either out: > > 1) I have a model named TestCase - > class TestCase < ActiveRecord::Base > belongs_to :test_suite > scope :queued, lambda { where("test_cases.suite_id IS NOT NULL") } > scope :assigned_to, lambda { |sid| where(:suite_id => sid) } > end > > The controller can interact with it perfectly fine. When trying to > display information from it in either the view or via the view helper > such as TestCase.all, I get a NoMethodError (undefined method `all''.) > If I call it with ::TestCase.all, that works. I had a theory that it > has something to do with the fact that it''s associated to another > model (belongs_to ...), I just can''t find anything to confirm that or > tell me why that happens. >You''re probably picking up one of the other TestCase classes that are part of rails or the ruby standard library (eg ActionView::TestCase)> > @artwork = Artwork.find(params[:id]) > value = params[:value].to_sym > @artwork.update_attributes(value => !...@artwork.method(value).call) > > That gives me a NoMethodError. However, if I add - if > @artwork.respond_to?(value) - then it works as expected. Again, I > can''t figure out why.Attribute accessors methods are only created when they are first used, so method doesn''t find them. If you just use send instead that that should work fine (since that will hit the method_messing code that creates those methods (which calling respond_to also does)) Fred> > Both items I get working using the mentioned methods, but again, I > feel like I''m really missing something important 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-/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.
Oh wow, I didn''t even see that that there was already a defined TestCase class. Well, that makes much more sense! So I''m not going insane, just ... blind. Good to know! As for send ... I thought I read once upon a time that send took more processing time or something similar. I guess it doesn''t matter if respond_to is doing essentially the same thing in the end. Either way .. Thanks. This clears up some things driving me insane! On Mon, Nov 22, 2010 at 4:45 PM, Frederick Cheung < frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Nov 22, 10:37 pm, Aedorn Varanis <aed...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I feel like I''m missing something rather important in both > > circumstances, but I can''t seem to figure either out: > > > > 1) I have a model named TestCase - > > class TestCase < ActiveRecord::Base > > belongs_to :test_suite > > scope :queued, lambda { where("test_cases.suite_id IS NOT NULL") } > > scope :assigned_to, lambda { |sid| where(:suite_id => sid) } > > end > > > > The controller can interact with it perfectly fine. When trying to > > display information from it in either the view or via the view helper > > such as TestCase.all, I get a NoMethodError (undefined method `all''.) > > If I call it with ::TestCase.all, that works. I had a theory that it > > has something to do with the fact that it''s associated to another > > model (belongs_to ...), I just can''t find anything to confirm that or > > tell me why that happens. > > > You''re probably picking up one of the other TestCase classes that are > part of rails or the ruby standard library (eg ActionView::TestCase) > > > > > @artwork = Artwork.find(params[:id]) > > value = params[:value].to_sym > > @artwork.update_attributes(value => !...@artwork.method(value).call) > > > > That gives me a NoMethodError. However, if I add - if > > @artwork.respond_to?(value) - then it works as expected. Again, I > > can''t figure out why. > > Attribute accessors methods are only created when they are first used, > so method doesn''t find them. If you just use send instead that that > should work fine (since that will hit the method_messing code that > creates those methods (which calling respond_to also does)) >> Fred > > > > Both items I get working using the mentioned methods, but again, I > > feel like I''m really missing something important 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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.