Hello, I cannot find the issue and it drives me crazy :( let''s simplify. I have 2 models: saving and purchase_type a *saving* corresponds to a *purchase_type* e.g. new sourcing or renegotiation a saving has exactly one purchase_type and a purchase_type has many savings. when I try to display the list of savings and their purchase type (name, not Id), i get the dreaded "You have a nil object when you didn''t expect it!". The weirdest thing is that it works for category and subcategory, but not for purchase type. Is this a camel casing issue? All the relevant code is below I''m getting mad, please help :) Thanks, P. Here''s the index.rhtml (extracts -- RoR tells me the issue is on the line with *****): <% @saving.each do |s|%> <tr> <td><%=s.id%></td> <td><%=s.country.name%></td> <td><%=s.country_reference%></td> <td><%=s.supplier%></td> <td><%=s.buyer%></td> <td><%=s.category.name%></td> <td><%=s.subcategory.name%></td> ***** <td><%=s.purchaseType.name %></td> the controller (saving_controller): class SavingController < ApplicationController def index @category = Category.find(:all).collect {|c| [ c.name, c.id ] } @subcategory = Subcategory.find(:all).collect {|c| [ c.name, c.id ] } @purchaseType = PurchaseType.find(:all).collect {|c| [ c.name, c.id ] } sort_order = params[:sort_by] sort_order ||= ''id'' # for default sort @saving = Saving.search(params[:search], params[:page], sort_order) end end the saving model (saving - table name = savings): class Saving < ActiveRecord::Base validates_presence_of :supplier, :a_saving, :a_spend, :country_id, :category_id, :subcategory_id, :buyer, :purchaseType_id, validates_numericality_of :a_saving, :a_spend belongs_to :category belongs_to :purchaseType belongs_to :subcategory def self.search(search, page, sort_order) search=''%'' if search=='''' || search==''Type your search term'' paginate :page => page, :conditions => [''supplier like ?'',"%#{search}%"], :order => sort_order end end the purchase_type model (model name = PurchaseType -table name purchase_types): class PurchaseType < ActiveRecord::Base validates_presence_of :name has_many :saving end --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Sun, Apr 5, 2009 at 8:46 AM, P <pierrelapree-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> the controller (saving_controller): > > class SavingController < ApplicationControllers/b SavingsController> class PurchaseType < ActiveRecord::Base> has_many :savings/b has_many :savings Try changing that and let us know what happens :-) -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, thanks hassan for the quick reply. I applied your suggestions + had to change a few other things (folder name for the views, some routes...) but that didn''t help either :( any other idea? thanks P. On 5 avr, 18:46, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sun, Apr 5, 2009 at 8:46 AM, P <pierrelap...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > the controller (saving_controller): > > > class SavingController < ApplicationController > > s/b SavingsController > > > class PurchaseType < ActiveRecord::Base > > has_many :saving > > s/b has_many :savings > > Try changing that and let us know what happens :-) > > -- > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Apr 5, 5:55 pm, P <pierrelap...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > thanks hassan for the quick reply. > I applied your suggestions + had to change a few other things (folder > name for the views, some routes...) but that didn''t help either :( >it should also be belongs_to :purchase_type rather than purchaseType but I don''t think that will actually make a difference (and if you made that change you would have to rename the column to purchase_type_id). Have you checked that you don''t simply have bad data in your database (ie a saving with a purchaseType_id for which there is no corresponding PurchaseType ? Fred> any other idea? > > thanks > P. > > On 5 avr, 18:46, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Sun, Apr 5, 2009 at 8:46 AM, P <pierrelap...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > the controller (saving_controller): > > > > class SavingController < ApplicationController > > > s/b SavingsController > > > > class PurchaseType < ActiveRecord::Base > > > has_many :saving > > > s/b has_many :savings > > > Try changing that and let us know what happens :-) > > > -- > > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, no crappy data. I really think i have a normalization issue :( I''ll try to change everything and see how it goes. thanks 8 P. On 5 avr, 19:08, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 5, 5:55 pm, P <pierrelap...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, > > thanks hassan for the quick reply. > > I applied your suggestions + had to change a few other things (folder > > name for the views, some routes...) but that didn''t help either :( > > it should also be belongs_to :purchase_type rather than purchaseType > but I don''t think that will actually make a difference (and if you > made that change you would have to rename the column to > purchase_type_id). > Have you checked that you don''t simply have bad data in your database > (ie a saving with a purchaseType_id for which there is no > corresponding PurchaseType ? > > Fred > > > any other idea? > > > thanks > > P. > > > On 5 avr, 18:46, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On Sun, Apr 5, 2009 at 8:46 AM, P <pierrelap...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > the controller (saving_controller): > > > > > class SavingController < ApplicationController > > > > s/b SavingsController > > > > > class PurchaseType < ActiveRecord::Base > > > > has_many :saving > > > > s/b has_many :savings > > > > Try changing that and let us know what happens :-) > > > > -- > > > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, i finally renamed everything (removed the mixed underscores / camel casing) and it works. thanks, P. On Apr 5, 7:25 pm, P <pierrelap...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > no crappy data. > > I really think i have a normalization issue :( > I''ll try to change everything and see how it goes. > > thanks 8 > P. > > On 5 avr, 19:08, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Apr 5, 5:55 pm, P <pierrelap...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi, > > > thanks hassan for the quick reply. > > > I applied your suggestions + had to change a few other things (folder > > > name for the views, some routes...) but that didn''t help either :( > > > it should also be belongs_to :purchase_type rather than purchaseType > > but I don''t think that will actually make a difference (and if you > > made that change you would have to rename the column to > > purchase_type_id). > > Have you checked that you don''t simply have bad data in your database > > (ie a saving with a purchaseType_id for which there is no > > corresponding PurchaseType ? > > > Fred > > > > any other idea? > > > > thanks > > > P. > > > > On 5 avr, 18:46, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On Sun, Apr 5, 2009 at 8:46 AM, P <pierrelap...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > the controller (saving_controller): > > > > > > class SavingController < ApplicationController > > > > > s/b SavingsController > > > > > > class PurchaseType < ActiveRecord::Base > > > > > has_many :saving > > > > > s/b has_many :savings > > > > > Try changing that and let us know what happens :-) > > > > > -- > > > > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8@public.gmane.orgm--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---