I have two tables. Let say headers and details. On headers_controller.rb I have has_many :details On details_controller.rb I have belongs_to :header I have in my model for header (just for testing): def list @headers = Headers.sort( "headers.kind ASC") end So when i run after loading the proper data a header.details.size it returns me the number of details for the selected header. But when I try to display header.details.size in a list view for the headers I get an arror saying "Unrecognized constant Header::Detail" I try to get this in the list with: <%= header.details.size %> What am I doing wrong? -- 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 17 March 2011 16:27, rhin0nt <rhino0nt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have two tables. Let say headers and details. > > On headers_controller.rb I have > > has_many :detailsThat should be in the model not the controller> > On details_controller.rb I have > > belongs_to :headerditto> > I have in my model for header (just for testing):This should be in the controller> > def list > @headers = Headers.sort( "headers.kind ASC")That should be Header (singular)> end > > So when i run after loading the proper data a header.details.size it > returns me the number of details for the selected header. > > But when I try to display header.details.size in a list view for the > headers I get an arror saying > "Unrecognized constant Header::Detail" > > I try to get this in the list with: > > <%= header.details.size %> > > What am I doing wrong? > > -- > 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. > >-- 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.
On 17 March 2011 17:39, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 17 March 2011 16:27, rhin0nt <rhino0nt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> I have two tables. Let say headers and details. >> >> On headers_controller.rb I have >> >> has_many :details > > That should be in the model not the controller > >> >> On details_controller.rb I have >> >> belongs_to :header > > ditto > >> >> I have in my model for header (just for testing): > > This should be in the controller > >> >> def list >> @headers = Headers.sort( "headers.kind ASC") > > That should be Header (singular)Also it should be order not sort Colin> >> end >> >> So when i run after loading the proper data a header.details.size it >> returns me the number of details for the selected header. >> >> But when I try to display header.details.size in a list view for the >> headers I get an arror saying >> "Unrecognized constant Header::Detail" >> >> I try to get this in the list with: >> >> <%= header.details.size %> >> >> What am I doing wrong? >> >> -- >> 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. >> >> >-- 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.