m getting an error "Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id" when i''m creating new record,like a topic has many discussions,when i''m creating a new discussions m getting that error..i already assign the topic id as foreign key in discussions controller....please sort out this problem.if u getting the same..how you rectify those errors..and in how many cases this errors are prone to occur??? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/zjIttg1BI8sJ. 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-US.
On Wed, Jul 4, 2012 at 12:23 AM, rocky <asharma182-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> m getting an error "Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id" > > when i''m creating new record,like a topic has many discussions,when i''m creating a new discussions m getting that error..i already assign the topic id as foreign key in discussions controller....please sort out this problem.if u getting the same..how you rectify those errors..and in how many cases this errors are prone to occur??? > > We need more information to help you , can you post part of the relevantcode? -- 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-US.
subjects has many pages subject controller code:: class SubjectController < ApplicationController def list @subjects = Subject.order("subjects.position ASC") end def show @subject = Subject.find(params[:id]) end def new @subject = Subject.new(:visible => ''false'') @subject_count = Subject.count + 1 end def create @subject = Subject.new(params[:subject]) if @subject.save redirect_to(:action => ''list'') else render(''new'') end end end page controller code:: class PageController < ApplicationController before_filter :find_subject def index list render(''list'') end def list @pages = Page.where(:subject_id => @subject.id) end def show @page = Page.find(params[:id]) end def new @page = Page.new(:subject_id => @subject.id) @page_count = @subject.pages.size + 1 @subjects = Subject.order(''position ASC'') end def create @page = Page.new(params[:page]) if @page.save redirect_to(:action => ''list'', :subject_id => @page.subject_id) else render(''new'') end end private def find_subject if params[:subject_id] @subject = Subject.find_by_id(params[:subject_id]) end end end this is my controller code and when m creating new page m getting dat error... -- 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-US.
On 4 July 2012 07:14, Abhishek Sharma <asharma182-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> class PageController < ApplicationController > > before_filter :find_subject > > def new > @page = Page.new(:subject_id => @subject.id) > @page_count = @subject.pages.size + 1 > @subjects = Subject.order(''position ASC'') > end > > private > def find_subject > if params[:subject_id] > @subject = Subject.find_by_id(params[:subject_id]) > end > end > > endYou''re calling find_subject on a before_filter, and it may or may not populate a @subject object depending on whether there''s a param value. But your action then goes on to expect there to definitely be an @subject instance variable. Put a breakpoint in find_subject, and see what the parameter values are. -- 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-US.
On 4 July 2012 05:23, rocky <asharma182-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> m getting an error "Called id for nil, which would mistakenly be 4 -- if you > really wanted the id of nil, use object_id" > > when i''m creating new record,like a topic has many discussions,when i''m > creating a new discussions m getting that error..i already assign the topic > id as foreign key in discussions controller....please sort out this > problem.if u getting the same..how you rectify those errors..and in how many > cases this errors are prone to occur???This means that you have some code some_object.id where some_object is nil. The error message should tell you which line is failing. Have a look at the Rails Guide on debugging for ideas on how to debug your code to find the problem. Colin -- 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-US.