I''m getting this error- ActiveRecord::RecordNotFound in PagesController#create Couldn''t find Course without an ID ------ Btw, the pages belongs to courses, and the courses has many pages Now, in my pages controller, for my create action, i have this-- def create @course = Course.find(params[:id]) @page = @course.pages.build(params[:page]) .... if and else stuff.... end Whats wrong? Why am i getting this message? Thanks, i really need help! -- 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.
Show your method and filters Sent from my iPhone On 04.04.2010, at 6:05, David Zhu <dzwestwindsor45-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m getting this error- > > ActiveRecord::RecordNotFound in PagesController#create > > Couldn''t find Course without an ID > > > ------ > > Btw, the pages belongs to courses, and the courses has many pages > > Now, in my pages controller, for my create action, i have this-- > > def create > > @course = Course.find(params[:id]) > @page = @course.pages.build(params[:page]) > > .... if and else stuff.... > > end > > > > Whats wrong? Why am i getting this message? Thanks, i really need > help! > > -- > 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 > . > 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.
I think because the record with that id is not existed in the database. You could check the database to to see whether there is a record with the id. Or you could also check the id value in the controller, is it valiable? On Sun, Apr 4, 2010 at 10:05 AM, David Zhu <dzwestwindsor45-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> I''m getting this error- > > ActiveRecord::RecordNotFound in PagesController#create > > Couldn''t find Course without an ID > > > ------ > > Btw, the pages belongs to courses, and the courses has many pages > > Now, in my pages controller, for my create action, i have this-- > > def create > > @course = Course.find(params[:id]) > @page = @course.pages.build(params[:page]) > > .... if and else stuff.... > > end > > > > Whats wrong? Why am i getting this message? Thanks, i really need help! > > -- > 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.
On Sat, Apr 3, 2010 at 7:05 PM, David Zhu <dzwestwindsor45-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m getting this error- > > ActiveRecord::RecordNotFound in PagesController#create > > Couldn''t find Course without an ID > > > ------ > > Btw, the pages belongs to courses, and the courses has many pages > > Now, in my pages controller, for my create action, i have this-- > > def create > > @course = Course.find(params[:id]) > @page = @course.pages.build(params[:page]) > > .... if and else stuff.... > > end > > > > Whats wrong? Why am i getting this message? Thanks, i really need help! > >David, you''re assuming that the first line in the method is successful after execution. Thus, I would recommend doing something like the following: def create @course = Course.find( params[:id] ) # The exception is thrown here. @page = @course.pages.build( params[:page] ) if @page.save flash[:notice] = "Successfully created page." redirect_to course_url( @page.course_id ) else render :action => ''new'' end rescue ActiveRecord::RecordNotFound => exception # The thrown exception is caught and dealt with here. logger.error( "Error: #{exception.message}" flash[:error] = "#{exception.message}" render :action => ''new'' end Next, you can test exception handling in the IRB by doing something as simple as the following:> def my_exceptional_method; Post.find( 2000 ); rescueActiveRecord::RecordNotFound => exception; puts exception.message; end> my_exceptional_methodLastly, I would recommend reading the relevant sections of "AWDwRails 3ed" by Dave Thomas et al. Good luck, -Conrad> -- > 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.
On Sun, Apr 4, 2010 at 12:24 AM, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sat, Apr 3, 2010 at 7:05 PM, David Zhu <dzwestwindsor45-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: > >> I''m getting this error- >> >> ActiveRecord::RecordNotFound in PagesController#create >> >> Couldn''t find Course without an ID >> >> >> ------ >> >> Btw, the pages belongs to courses, and the courses has many pages >> >> Now, in my pages controller, for my create action, i have this-- >> >> def create >> >> @course = Course.find(params[:id]) >> @page = @course.pages.build(params[:page]) >> >> .... if and else stuff.... >> >> end >> >> >> >> Whats wrong? Why am i getting this message? Thanks, i really need help! >> >> > David, you''re assuming that the first line in the method is successful > after > execution. Thus, I would recommend doing something like the following: > > def create > > @course = Course.find( params[:id] ) # The exception is thrown here. > @page = @course.pages.build( params[:page] ) > > if @page.save > flash[:notice] = "Successfully created page." > redirect_to course_url( @page.course_id ) > else > render :action => ''new'' > end > > rescue ActiveRecord::RecordNotFound => exception # The thrown exception > is caught and dealt with here. > logger.error( "Error: #{exception.message}" > flash[:error] = "#{exception.message}" > render :action => ''new'' > end > > Next, you can test exception handling in the IRB by doing something as > simple as the following: > > > def my_exceptional_method; Post.find( 2000 ); rescue > ActiveRecord::RecordNotFound => exception; puts exception.message; end >Correction, the above line should be the following:> def my_exceptional_method; Course.find( 2000 ); rescueActiveRecord::RecordNotFound => exception; puts exception.message; end Good luck, -Conrad> > my_exceptional_method > > Lastly, I would recommend reading the relevant sections of "AWDwRails 3ed" > by Dave Thomas et al. > > Good luck, > > -Conrad > > >> -- >> >> 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.
Hi David This error is mainly because your not getting id in the create function Please follow the following steps, i think this will solve your problem. I hope you configured your routes like this map.resources :courses do |course| course.resources :pages end <%form_for :page,:url=>course_pages_path(@course) do %> <%end%> in controller def new @course = Course.find(params[:course_id]) end def create @course = Course.find(params[:course_id]) @page = @course.pages.find(params[:page]) end Keep rocking! David Zhu wrote:> I''m getting this error- > > ActiveRecord::RecordNotFound in PagesController#create > > Couldn''t find Course without an ID > > > ------ > > Btw, the pages belongs to courses, and the courses has many pages > > Now, in my pages controller, for my create action, i have this-- > > def create > > @course = Course.find(params[:id]) > @page = @course.pages.build(params[:page]) > > .... if and else stuff.... > > end > > > > Whats wrong? Why am i getting this message? Thanks, i really need help!-- Posted via http://www.ruby-forum.com/. -- 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 Sun, Apr 4, 2010 at 12:39 AM, Srijith nair <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi David > This error is mainly because your not getting id in the create function > Please follow the following steps, i think this will solve your problem. > > I hope you configured your routes like this > map.resources :courses do |course| > course.resources :pages > end > > <%form_for :page,:url=>course_pages_path(@course) do %> > <%end%> > > in controller > def new > @course = Course.find(params[:course_id]) > end > > def create > @course = Course.find(params[:course_id]) > @page = @course.pages.find(params[:page]) > end > >Srijith, the second isn''t correct because you''re trying to find a page that doesn''t exist the database. Thus, this will generate ActiveRecord::RecordNotFound as would the first line if it doesn''t exist and the second should like like the following: @page = @course.pages.build( params[:page] ) @David - make sure that you have a ''new'' method on the PagesController defined as follows: def new @course = Course.find( params[:course_id] ) @page = @course.pages.build end Good luck, -Conrad> Keep rocking! > > David Zhu wrote: > > I''m getting this error- > > > > ActiveRecord::RecordNotFound in PagesController#create > > > > Couldn''t find Course without an ID > > > > > > ------ > > > > Btw, the pages belongs to courses, and the courses has many pages > > > > Now, in my pages controller, for my create action, i have this-- > > > > def create > > > > @course = Course.find(params[:id]) > > @page = @course.pages.build(params[:page]) > > > > .... if and else stuff.... > > > > end > > > > > > > > Whats wrong? Why am i getting this message? Thanks, i really need help! > > -- > Posted via http://www.ruby-forum.com/. > > -- > 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.
Sorry! that was new method by mistake i had written it as find. map.resources :courses do |course| course.resources :pages end <%form_for :page,:url=>course_pages_path(@course) do %> <%end%> in controller def new @course = Course.find(params[:course_id]) end def create @course = Course.find(params[:course_id]) @page = @course.pages.new(params[:page]) @page.save end Keep rocking Conrad Taylor wrote:> On Sun, Apr 4, 2010 at 12:39 AM, Srijith nair <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > wrote: > >> <%end%> >> >> > Srijith, the second isn''t correct because you''re > trying to find a page that doesn''t exist the database. > Thus, this will generate ActiveRecord::RecordNotFound > as would the first line if it doesn''t exist and the second > should like like the following: > > @page = @course.pages.build( params[:page] ) > > @David - make sure that you have a ''new'' method > on the PagesController defined as follows: > > def new > @course = Course.find( params[:course_id] ) > @page = @course.pages.build > end > > Good luck, > > -Conrad-- Posted via http://www.ruby-forum.com/. -- 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.
can i comment out- map.resources :pages in my routes? or do i need that? On Apr 4, 4:11 am, Srijith nair <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Sorry! > that was new method by mistake i had written it as find. > map.resources :courses do |course| > course.resources :pages > end > > <%form_for :page,:url=>course_pages_path(@course) do %> > <%end%> > > in controller > def new > @course = Course.find(params[:course_id]) > end > > def create > @course = Course.find(params[:course_id]) > @page = @course.pages.new(params[:page]) > @page.save > end > > Keep rocking > > > > Conrad Taylor wrote: > > On Sun, Apr 4, 2010 at 12:39 AM, Srijith nair <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > > wrote: > > >> <%end%> > > > Srijith, the second isn''t correct because you''re > > trying to find a page that doesn''t exist the database. > > Thus, this will generate ActiveRecord::RecordNotFound > > as would the first line if it doesn''t exist and the second > > should like like the following: > > > @page = @course.pages.build( params[:page] ) > > > @David- make sure that you have a ''new'' method > > on the PagesController defined as follows: > > > def new > > @course = Course.find( params[:course_id] ) > > @page = @course.pages.build > > end > > > Good luck, > > > -Conrad > > -- > Posted viahttp://www.ruby-forum.com/.-- 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.
i got it- http://www.akitaonrails.com/2007/12/12/rolling-with-rails-2-0-the-first-full-tutorial Thanks guys for all the help On Apr 4, 5:01 pm, David Zhu <dzwestwindso...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> can i comment out- map.resources :pages in my routes? or do i need > that? > > On Apr 4, 4:11 am, Srijith nair <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > > Sorry! > > that was new method by mistake i had written it as find. > > map.resources :courses do |course| > > course.resources :pages > > end > > > <%form_for :page,:url=>course_pages_path(@course) do %> > > <%end%> > > > in controller > > def new > > @course = Course.find(params[:course_id]) > > end > > > def create > > @course = Course.find(params[:course_id]) > > @page = @course.pages.new(params[:page]) > > @page.save > > end > > > Keep rocking > > > Conrad Taylor wrote: > > > On Sun, Apr 4, 2010 at 12:39 AM, Srijith nair <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > > > wrote: > > > >> <%end%> > > > > Srijith, the second isn''t correct because you''re > > > trying to find a page that doesn''t exist the database. > > > Thus, this will generate ActiveRecord::RecordNotFound > > > as would the first line if it doesn''t exist and the second > > > should like like the following: > > > > @page = @course.pages.build( params[:page] ) > > > > @David- make sure that you have a ''new'' method > > > on the PagesController defined as follows: > > > > def new > > > @course = Course.find( params[:course_id] ) > > > @page = @course.pages.build > > > end > > > > Good luck, > > > > -Conrad > > > -- > > Posted viahttp://www.ruby-forum.com/.-- 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 Sun, Apr 4, 2010 at 2:01 PM, David Zhu <dzwestwindsor45-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> can i comment out- map.resources :pages in my routes? or do i need > that? > >David, it really depends on what you''re trying to do. It seems that you were using nested resources. Thus, I would expect the following within your routes.rb: map.resources :courses, :has_many => :pages map.root :courses Good luck, -Conrad> On Apr 4, 4:11 am, Srijith nair <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > Sorry! > > that was new method by mistake i had written it as find. > > map.resources :courses do |course| > > course.resources :pages > > end > > > > <%form_for :page,:url=>course_pages_path(@course) do %> > > <%end%> > > > > in controller > > def new > > @course = Course.find(params[:course_id]) > > end > > > > def create > > @course = Course.find(params[:course_id]) > > @page = @course.pages.new(params[:page]) > > @page.save > > end > > > > Keep rocking > > > > > > > > Conrad Taylor wrote: > > > On Sun, Apr 4, 2010 at 12:39 AM, Srijith nair <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > > > wrote: > > > > >> <%end%> > > > > > Srijith, the second isn''t correct because you''re > > > trying to find a page that doesn''t exist the database. > > > Thus, this will generate ActiveRecord::RecordNotFound > > > as would the first line if it doesn''t exist and the second > > > should like like the following: > > > > > @page = @course.pages.build( params[:page] ) > > > > > @David- make sure that you have a ''new'' method > > > on the PagesController defined as follows: > > > > > def new > > > @course = Course.find( params[:course_id] ) > > > @page = @course.pages.build > > > end > > > > > Good luck, > > > > > -Conrad > > > > -- > > Posted viahttp://www.ruby-forum.com/. > > -- > 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.
On Sun, Apr 4, 2010 at 4:17 PM, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sun, Apr 4, 2010 at 2:01 PM, David Zhu <dzwestwindsor45-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: > >> can i comment out- map.resources :pages in my routes? or do i need >> that? >> >> > David, it really depends on what you''re trying to do. It seems that you > were using > nested resources. Thus, I would expect the following within your > routes.rb: > > map.resources :courses, :has_many => :pages > map.root :courses > >Correction, it should be map.root :controller => "courses" -Conrad> Good luck, > > -Conrad > > >> On Apr 4, 4:11 am, Srijith nair <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> > Sorry! >> > that was new method by mistake i had written it as find. >> > map.resources :courses do |course| >> > course.resources :pages >> > end >> > >> > <%form_for :page,:url=>course_pages_path(@course) do %> >> > <%end%> >> > >> > in controller >> > def new >> > @course = Course.find(params[:course_id]) >> > end >> > >> > def create >> > @course = Course.find(params[:course_id]) >> > @page = @course.pages.new(params[:page]) >> > @page.save >> > end >> > >> > Keep rocking >> > >> > >> > >> > Conrad Taylor wrote: >> > > On Sun, Apr 4, 2010 at 12:39 AM, Srijith nair <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> >> > > wrote: >> > >> > >> <%end%> >> > >> > > Srijith, the second isn''t correct because you''re >> > > trying to find a page that doesn''t exist the database. >> > > Thus, this will generate ActiveRecord::RecordNotFound >> > > as would the first line if it doesn''t exist and the second >> > > should like like the following: >> > >> > > @page = @course.pages.build( params[:page] ) >> > >> > > @David- make sure that you have a ''new'' method >> > > on the PagesController defined as follows: >> > >> > > def new >> > > @course = Course.find( params[:course_id] ) >> > > @page = @course.pages.build >> > > end >> > >> > > Good luck, >> > >> > > -Conrad >> > >> > -- >> > Posted viahttp://www.ruby-forum.com/. >> >> -- >> 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.
thanks, that really helped! rated all of you guys 5 stars :) On Apr 4, 7:20 pm, Conrad Taylor <conra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sun, Apr 4, 2010 at 4:17 PM, Conrad Taylor <conra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > On Sun, Apr 4, 2010 at 2:01 PM, David Zhu <dzwestwindso...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: > > >> can i comment out- map.resources :pages in my routes? or do i need > >> that? > > > David, it really depends on what you''re trying to do. It seems that you > > were using > > nested resources. Thus, I would expect the following within your > > routes.rb: > > > map.resources :courses, :has_many => :pages > > map.root :courses > > Correction, it should be > > map.root :controller => "courses" > > -Conrad > > > Good luck, > > > -Conrad > > >> On Apr 4, 4:11 am, Srijith nair <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> > Sorry! > >> > that was new method by mistake i had written it as find. > >> > map.resources :courses do |course| > >> > course.resources :pages > >> > end > > >> > <%form_for :page,:url=>course_pages_path(@course) do %> > >> > <%end%> > > >> > in controller > >> > def new > >> > @course = Course.find(params[:course_id]) > >> > end > > >> > def create > >> > @course = Course.find(params[:course_id]) > >> > @page = @course.pages.new(params[:page]) > >> > @page.save > >> > end > > >> > Keep rocking > > >> > Conrad Taylor wrote: > >> > > On Sun, Apr 4, 2010 at 12:39 AM, Srijith nair <li...-fsXkhYbjdPsM1dTnIXmMWg@public.gmane.orgm> > >> > > wrote: > > >> > >> <%end%> > > >> > > Srijith, the second isn''t correct because you''re > >> > > trying to find a page that doesn''t exist the database. > >> > > Thus, this will generate ActiveRecord::RecordNotFound > >> > > as would the first line if it doesn''t exist and the second > >> > > should like like the following: > > >> > > @page = @course.pages.build( params[:page] ) > > >> > > @David- make sure that you have a ''new'' method > >> > > on the PagesController defined as follows: > > >> > > def new > >> > > @course = Course.find( params[:course_id] ) > >> > > @page = @course.pages.build > >> > > end > > >> > > Good luck, > > >> > > -Conrad > > >> > -- > >> > Posted viahttp://www.ruby-forum.com/. > > >> -- > >> 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<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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Srijith nair wrote:> Hi David > This error is mainly because your not getting id in the create function > Please follow the following steps, i think this will solve your problem. > > I hope you configured your routes like this > map.resources :courses do |course| > course.resources :pages > end > > <%form_for :page,:url=>course_pages_path(@course) do %> > <%end%> > > in controller > def new > @course = Course.find(params[:course_id]) > end > > def create > @course = Course.find(params[:course_id]) > @page = @course.pages.find(params[:page]) > end > > Keep rocking! > > David Zhu wrote: >> I''m getting this error- >> >> ActiveRecord::RecordNotFound in PagesController#create >> >> Couldn''t find Course without an IDI have a very similar problem I think. I Can''t find Story without an ID. This is from my email_controller.rb def correspond user = @current_user story = Story.find(params[:id]) recipient = story.user @title = "Email @current_user.login" if param_posted?(:message) @message = Message.new(params[:message]) if @message.valid? UserMailer.deliver_message( :user => user, :recipient => recipient, :message => @message, :user_url => user, :reply_url => url_for(:action => "correspond", :id => user.login) ) flash[:notice] = "Email sent." redirect_to :action => "index", :controller => "stories" end end end The problem is in the third line. Any help would be much appreciated. -- Posted via http://www.ruby-forum.com/. -- 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 30 June 2010 17:47, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Srijith nair wrote: > >... > I have a very similar problem I think. I Can''t find Story without an ID. > > This is from my email_controller.rb > > def correspond > user = @current_user > story = Story.find(params[:id]) >... > > The problem is in the third line.The error says that it cannot find Story without an id, you are asking find to use params[:id]. So possibly params[:id] is not valid. What is the value of params[:id]? Look in development.log to find out. Also have a look at the rails guide on debugging, it will show you how you can use ruby-debug to break into your code and inspect data, so you can see what params[:id] is. In this case the log may be enough though. 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law wrote:> On 30 June 2010 17:47, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>... >> >> The problem is in the third line. >. What> is the value of params[:id]? Look in development.log to find out. >This is all I have in the log: Processing EmailController#correspond (for 127.0.0.1 at 2010-06-30 19:32:58) [GET] [4;36;1mUser Load (0.5ms) [0m [0;1mSELECT * FROM "users" WHERE ("users"."id" = 1) LIMIT 1 [0m ActiveRecord::RecordNotFound (Couldn''t find Story without an ID): app/controllers/email_controller.rb:23:in `correspond'' Rendered rescues/_trace (57.5ms) Rendered rescues/_request_and_response (0.4ms) Rendering rescues/layout (not_found) I''ll look at the debugging section -- Posted via http://www.ruby-forum.com/. -- 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 30 June 2010 20:37, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote: >> On 30 June 2010 17:47, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>>... >>> >>> The problem is in the third line. >> > . What >> is the value of params[:id]? Look in development.log to find out. >> > This is all I have in the log: > > Processing EmailController#correspond (for 127.0.0.1 at 2010-06-30 > 19:32:58) [GET]The params should be in here, since there is nothing I suggest that you have not passed an id in the link (or you have attempted to but it''s value is nil). Colin> [4;36;1mUser Load (0.5ms) [0m [0;1mSELECT * FROM "users" WHERE > ("users"."id" = 1) LIMIT 1 [0m > > ActiveRecord::RecordNotFound (Couldn''t find Story without an ID): > app/controllers/email_controller.rb:23:in `correspond'' > > Rendered rescues/_trace (57.5ms) > Rendered rescues/_request_and_response (0.4ms) > Rendering rescues/layout (not_found) > > I''ll look at the debugging section > -- > Posted via http://www.ruby-forum.com/. > > -- > 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.