Hello there, I am looking to be able to delete posts from within my account page. I have a destroy action within the posts controller, which looks like this: def destroy @post = Post.find(params[:user_id]) @post.destroy respond_to do |format| format.html { redirect_to :controller => "profile"} format.xml { head :ok } end end And I also have the button which is clicked to delete a post. <% form_tag(:controller => "posts", :action => "destroy", :confirm => ''Are you sure?'') do %> <%= submit_tag("Delete") %> However - when i click ''delete'' I get the following error: ActiveRecord::RecordNotFound in PostsController#destroy Couldn''t find Post without an ID I changed ''@post = Post.find(params[:user_id])'' to only have :id as a param, but that returned with the same issue. Can anyone help? Many Thanks -- 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 don''t see where you are actually passing in the id! We do something like this: <%= link_to image_tag("cross.png"), post, :confirm => ''Are you sure?'', :method => :delete, :title => "Delete this post" %> That gives us an icon to click on and will delete the post by calling PostsController#destroy which looks like: def destroy @post = Post.find(params[:id]) @post.destroy respond_to do |format| format.html { redirect_to(posts_url) } format.xml { head :ok } end end On Dec 5, 4:40 pm, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Hello there, > > I am looking to be able to delete posts from within my account page. > > I have a destroy action within the posts controller, which looks like > this: > > def destroy > @post = Post.find(params[:user_id]) > @post.destroy > > respond_to do |format| > format.html { redirect_to :controller => "profile"} > format.xml { head :ok } > end > end > > And I also have the button which is clicked to delete a post. > > <% form_tag(:controller => "posts", :action => "destroy", :confirm => > ''Are you sure?'') do %> > <%= submit_tag("Delete") %> > > However - when i click ''delete'' I get the following error: > > ActiveRecord::RecordNotFound in PostsController#destroy > > Couldn''t find Post without an ID > > I changed ''@post = Post.find(params[:user_id])'' to only have :id as a > param, but that returned with the same issue. > > Can anyone help? > > Many Thanks-- 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.
It doesnt looks like the form has the id parameter for the Post. Kristian 2009/12/5 RubyonRails_newbie <craigwesty79-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>:> Hello there, > > I am looking to be able to delete posts from within my account page. > > I have a destroy action within the posts controller, which looks like > this: > > def destroy > @post = Post.find(params[:user_id]) > -cw0y+/iDTYOv9pIUa/Yw3w@public.gmane.org > > respond_to do |format| > format.html { redirect_to :controller => "profile"} > format.xml { head :ok } > end > end > > And I also have the button which is clicked to delete a post. > > <% form_tag(:controller => "posts", :action => "destroy", :confirm => > ''Are you sure?'') do %> > <%= submit_tag("Delete") %> > > However - when i click ''delete'' I get the following error: > > ActiveRecord::RecordNotFound in PostsController#destroy > > Couldn''t find Post without an ID > > I changed ''@post = Post.find(params[:user_id])'' to only have :id as a > param, but that returned with the same issue. > > Can anyone help? > > Many Thanks > > -- > > 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.
Sorry forgot to say that in the view that line is inside an iterator: <% for post in @posts %> <%= link_to image_tag("cross.png"), post, :confirm => ''Are you sure?'', :method => :delete, :title => "Delete this post" %> <% end %> where @posts is set by: @posts = Post.all in the PostsController#index method. On Dec 5, 4:58 pm, phil <p...-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> wrote:> I don''t see where you are actually passing in the id! > > We do something like this: > > <%= link_to image_tag("cross.png"), post, :confirm => ''Are you > sure?'', :method => :delete, :title => "Delete this post" %> > > That gives us an icon to click on and will delete the post by calling > PostsController#destroy > > which looks like: > > def destroy > @post = Post.find(params[:id]) > @post.destroy > > respond_to do |format| > format.html { redirect_to(posts_url) } > format.xml { head :ok } > end > end > > On Dec 5, 4:40 pm, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > wrote: > > > > > Hello there, > > > I am looking to be able to delete posts from within my account page. > > > I have a destroy action within the posts controller, which looks like > > this: > > > def destroy > > @post = Post.find(params[:user_id]) > > @post.destroy > > > respond_to do |format| > > format.html { redirect_to :controller => "profile"} > > format.xml { head :ok } > > end > > end > > > And I also have the button which is clicked to delete a post. > > > <% form_tag(:controller => "posts", :action => "destroy", :confirm => > > ''Are you sure?'') do %> > > <%= submit_tag("Delete") %> > > > However - when i click ''delete'' I get the following error: > > > ActiveRecord::RecordNotFound in PostsController#destroy > > > Couldn''t find Post without an ID > > > I changed ''@post = Post.find(params[:user_id])'' to only have :id as a > > param, but that returned with the same issue. > > > Can anyone help? > > > Many Thanks-- 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.
Cool - thank you for that. It makes sense to me now. What I now have is this: <%= image_tag ("delete.png") %> <%= link_to "Delete post?", { :controller => "posts", :action => "delete", :id => @posts.id }, :confirm => "Really delete?" %> | This successfully deletes the posts, one at a time until they have all gone. However, once the last post of that user has been deleted, I get an error: Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id I know this is because it cannot find any posts for that post.id, but is there a good if else statement i can add to it to render the profile page once all have been erased? I''ve looked over it, but am a bit lost.. THanks again On 5 Dec, 16:00, phil <p...-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> wrote:> Sorry forgot to say that in the view that line is inside an iterator: > > <% for post in @posts %> > <%= link_to image_tag("cross.png"), post, :confirm => ''Are you > sure?'', :method => :delete, :title => "Delete this post" %> > <% end %> > > where @posts is set by: > @posts = Post.all > in the PostsController#index method. > > On Dec 5, 4:58 pm, phil <p...-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> wrote: > > > > > I don''t see where you are actually passing in the id! > > > We do something like this: > > > <%= link_to image_tag("cross.png"), post, :confirm => ''Are you > > sure?'', :method => :delete, :title => "Delete this post" %> > > > That gives us an icon to click on and will delete the post by calling > > PostsController#destroy > > > which looks like: > > > def destroy > > @post = Post.find(params[:id]) > > @post.destroy > > > respond_to do |format| > > format.html { redirect_to(posts_url) } > > format.xml { head :ok } > > end > > end > > > On Dec 5, 4:40 pm, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > > wrote: > > > > Hello there, > > > > I am looking to be able to delete posts from within my account page. > > > > I have a destroy action within the posts controller, which looks like > > > this: > > > > def destroy > > > @post = Post.find(params[:user_id]) > > > @post.destroy > > > > respond_to do |format| > > > format.html { redirect_to :controller => "profile"} > > > format.xml { head :ok } > > > end > > > end > > > > And I also have the button which is clicked to delete a post. > > > > <% form_tag(:controller => "posts", :action => "destroy", :confirm => > > > ''Are you sure?'') do %> > > > <%= submit_tag("Delete") %> > > > > However - when i click ''delete'' I get the following error: > > > > ActiveRecord::RecordNotFound in PostsController#destroy > > > > Couldn''t find Post without an ID > > > > I changed ''@post = Post.find(params[:user_id])'' to only have :id as a > > > param, but that returned with the same issue. > > > > Can anyone help? > > > > Many Thanks-- 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.
Without seeing your view, I''ll guess that you''re using "for foo in @foo do" ...if you use "@foo.each do |foo|" it should work, since .each doesn''t return an error on nil like ''for'' does. -eric On Dec 5, 9:00 am, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Cool - thank you for that. It makes sense to me now. > > What I now have is this: > > <%= image_tag ("delete.png") %> > <%= link_to "Delete post?", > { :controller => "posts", :action => "delete", > :id => @posts.id }, > :confirm => "Really delete?" %> | > > This successfully deletes the posts, one at a time until they have all > gone. However, once the last post of that user has been deleted, I get > an error: > > Called id for nil, which would mistakenly be 4 -- if you really wanted > the id of nil, use object_id > > I know this is because it cannot find any posts for that post.id, but > is there a good if else statement i can add to it to render the > profile page once all have been erased? > > I''ve looked over it, but am a bit lost.. > > THanks again > > On 5 Dec, 16:00, phil <p...-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> wrote: > > > Sorry forgot to say that in the view that line is inside an iterator: > > > <% for post in @posts %> > > <%= link_to image_tag("cross.png"), post, :confirm => ''Are you > > sure?'', :method => :delete, :title => "Delete this post" %> > > <% end %> > > > where @posts is set by: > > @posts = Post.all > > in the PostsController#index method. > > > On Dec 5, 4:58 pm, phil <p...-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> wrote: > > > > I don''t see where you are actually passing in the id! > > > > We do something like this: > > > > <%= link_to image_tag("cross.png"), post, :confirm => ''Are you > > > sure?'', :method => :delete, :title => "Delete this post" %> > > > > That gives us an icon to click on and will delete the post by calling > > > PostsController#destroy > > > > which looks like: > > > > def destroy > > > @post = Post.find(params[:id]) > > > @post.destroy > > > > respond_to do |format| > > > format.html { redirect_to(posts_url) } > > > format.xml { head :ok } > > > end > > > end > > > > On Dec 5, 4:40 pm, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > > > wrote: > > > > > Hello there, > > > > > I am looking to be able to delete posts from within my account page. > > > > > I have a destroy action within the posts controller, which looks like > > > > this: > > > > > def destroy > > > > @post = Post.find(params[:user_id]) > > > > @post.destroy > > > > > respond_to do |format| > > > > format.html { redirect_to :controller => "profile"} > > > > format.xml { head :ok } > > > > end > > > > end > > > > > And I also have the button which is clicked to delete a post. > > > > > <% form_tag(:controller => "posts", :action => "destroy", :confirm => > > > > ''Are you sure?'') do %> > > > > <%= submit_tag("Delete") %> > > > > > However - when i click ''delete'' I get the following error: > > > > > ActiveRecord::RecordNotFound in PostsController#destroy > > > > > Couldn''t find Post without an ID > > > > > I changed ''@post = Post.find(params[:user_id])'' to only have :id as a > > > > param, but that returned with the same issue. > > > > > Can anyone help? > > > > > Many Thanks-- 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.
my view is: <%= image_tag ("delete.png") %> <%= link_to "Delete post?", { :controller => "posts", :action => "delete", :id => @posts.id }, :confirm => "Really delete?" %> | i''ve tried to add <% if Posts.exists? %> before this so it would only display the delete icon if there are posts to delete... however, this also doesn''t work.. full code: <% if Posts.exists? %> <%= image_tag ("delete.png") %> <%= link_to "Delete post?", { :controller => "posts", :action => "delete", :id => @posts.id }, :confirm => "Really delete?" %> | <% else %> <%= image_tag ("another_image.png") %> <% end %> On 5 Dec, 17:23, Eric <ericgh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Without seeing your view, I''ll guess that you''re using "for foo in > @foo do" ...if you use "@foo.each do |foo|" it should work, > since .each doesn''t return an error on nil like ''for'' does. > > -eric > > On Dec 5, 9:00 am, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > wrote: > > > > > Cool - thank you for that. It makes sense to me now. > > > What I now have is this: > > > <%= image_tag ("delete.png") %> > > <%= link_to "Delete post?", > > { :controller => "posts", :action => "delete", > > :id => @posts.id }, > > :confirm => "Really delete?" %> | > > > This successfully deletes the posts, one at a time until they have all > > gone. However, once the last post of that user has been deleted, I get > > an error: > > > Called id for nil, which would mistakenly be 4 -- if you really wanted > > the id of nil, use object_id > > > I know this is because it cannot find any posts for that post.id, but > > is there a good if else statement i can add to it to render the > > profile page once all have been erased? > > > I''ve looked over it, but am a bit lost.. > > > THanks again > > > On 5 Dec, 16:00, phil <p...-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> wrote: > > > > Sorry forgot to say that in the view that line is inside an iterator: > > > > <% for post in @posts %> > > > <%= link_to image_tag("cross.png"), post, :confirm => ''Are you > > > sure?'', :method => :delete, :title => "Delete this post" %> > > > <% end %> > > > > where @posts is set by: > > > @posts = Post.all > > > in the PostsController#index method. > > > > On Dec 5, 4:58 pm, phil <p...-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> wrote: > > > > > I don''t see where you are actually passing in the id! > > > > > We do something like this: > > > > > <%= link_to image_tag("cross.png"), post, :confirm => ''Are you > > > > sure?'', :method => :delete, :title => "Delete this post" %> > > > > > That gives us an icon to click on and will delete the post by calling > > > > PostsController#destroy > > > > > which looks like: > > > > > def destroy > > > > @post = Post.find(params[:id]) > > > > @post.destroy > > > > > respond_to do |format| > > > > format.html { redirect_to(posts_url) } > > > > format.xml { head :ok } > > > > end > > > > end > > > > > On Dec 5, 4:40 pm, RubyonRails_newbie <craigwest...-gM/Ye1E23myhRSP0FMvGiw@public.gmane.orgm> > > > > wrote: > > > > > > Hello there, > > > > > > I am looking to be able to delete posts from within my account page. > > > > > > I have a destroy action within the posts controller, which looks like > > > > > this: > > > > > > def destroy > > > > > @post = Post.find(params[:user_id]) > > > > > @post.destroy > > > > > > respond_to do |format| > > > > > format.html { redirect_to :controller => "profile"} > > > > > format.xml { head :ok } > > > > > end > > > > > end > > > > > > And I also have the button which is clicked to delete a post. > > > > > > <% form_tag(:controller => "posts", :action => "destroy", :confirm => > > > > > ''Are you sure?'') do %> > > > > > <%= submit_tag("Delete") %> > > > > > > However - when i click ''delete'' I get the following error: > > > > > > ActiveRecord::RecordNotFound in PostsController#destroy > > > > > > Couldn''t find Post without an ID > > > > > > I changed ''@post = Post.find(params[:user_id])'' to only have :id as a > > > > > param, but that returned with the same issue. > > > > > > Can anyone help? > > > > > > Many Thanks-- 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 Sat, Dec 5, 2009 at 10:40 AM, RubyonRails_newbie <craigwesty79-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Hello there, > > I am looking to be able to delete posts from within my account page. > > I have a destroy action within the posts controller, which looks like > this: > > def destroy > @post = Post.find(params[:user_id]) > -cw0y+/iDTYOv9pIUa/Yw3w@public.gmane.org > > respond_to do |format| > format.html { redirect_to :controller => "profile"} > format.xml { head :ok } > end > end > > And I also have the button which is clicked to delete a post. > > <% form_tag(:controller => "posts", :action => "destroy", :confirm => > ''Are you sure?'') do %> > <%= submit_tag("Delete") %> > > However - when i click ''delete'' I get the following error: > > ActiveRecord::RecordNotFound in PostsController#destroy > > Couldn''t find Post without an ID > > I changed ''@post = Post.find(params[:user_id])'' to only have :id as a > param, but that returned with the same issue. > > Can anyone help?I see two problems here. 1) In the controller you are using params[:user_id] when it should be params[:id] 2) Your form isn''t telling the controller what to delete. instead of <% form_tag(:controller => "posts", :action => "destroy", :confirm => ''Are you sure?'') do %> <%= submit_tag("Delete") %> <% end %> maybe <% form_for @post, :url => {:action => ''destroy''} do %> <%= submit_tag("Delete", :confirm => ''Are you sure?'' %> <% end %> -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Ive since updated my controller to :id THe posts delete fine, until there are no posts left for that id to delete, then I get the error: Showing app/views/user/index.html.erb where line #40 raised: Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id I need an if posts.exists? or someting similar to allow the page to render regardless of the number of posts... On 5 Dec, 17:49, Rick DeNatale <rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sat, Dec 5, 2009 at 10:40 AM, RubyonRails_newbie > > > > > > <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > Hello there, > > > I am looking to be able to delete posts from within my account page. > > > I have a destroy action within the posts controller, which looks like > > this: > > > def destroy > > @post = Post.find(params[:user_id]) > > -cw0y+/iDTYOv9pIUa/Yw3w@public.gmane.org > > > respond_to do |format| > > format.html { redirect_to :controller => "profile"} > > format.xml { head :ok } > > end > > end > > > And I also have the button which is clicked to delete a post. > > > <% form_tag(:controller => "posts", :action => "destroy", :confirm => > > ''Are you sure?'') do %> > > <%= submit_tag("Delete") %> > > > However - when i click ''delete'' I get the following error: > > > ActiveRecord::RecordNotFound in PostsController#destroy > > > Couldn''t find Post without an ID > > > I changed ''@post = Post.find(params[:user_id])'' to only have :id as a > > param, but that returned with the same issue. > > > Can anyone help? > > I see two problems here. > > 1) In the controller you are using params[:user_id] when it should be > params[:id] > > 2) Your form isn''t telling the controller what to delete. > instead of > <% form_tag(:controller => "posts", :action => "destroy", :confirm => > ''Are you sure?'') do %> > <%= submit_tag("Delete") %> > <% end %> > > maybe > > <% form_for @post, :url => {:action => ''destroy''} do %> > <%= submit_tag("Delete", :confirm => ''Are you sure?'' %> > <% end %> > -- > Rick DeNatale > > Blog:http://talklikeaduck.denhaven2.com/ > Twitter:http://twitter.com/RickDeNatale > WWR:http://www.workingwithrails.com/person/9021-rick-denatale > LinkedIn:http://www.linkedin.com/in/rickdenatale-- 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 Sat, Dec 5, 2009 at 12:54 PM, RubyonRails_newbie <craigwesty79-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Ive since updated my controller to :id > > THe posts delete fine, until there are no posts left for that id to > delete, then I get the error: > Showing app/views/user/index.html.erb where line #40 raised: > > Called id for nil, which would mistakenly be 4 -- if you really wanted > the id of nil, use object_id > > I need an if posts.exists? or someting similar to allow the page to > render regardless of the number of posts...@post.destroy if @post -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Nope - sorry - this doesn''t work either. I will have to do some more digging about I think. THanks anyway... On 5 Dec, 18:10, Rick DeNatale <rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sat, Dec 5, 2009 at 12:54 PM, RubyonRails_newbie > > <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > Ive since updated my controller to :id > > > THe posts delete fine, until there are no posts left for that id to > > delete, then I get the error: > > Showing app/views/user/index.html.erb where line #40 raised: > > > Called id for nil, which would mistakenly be 4 -- if you really wanted > > the id of nil, use object_id > > > I need an if posts.exists? or someting similar to allow the page to > > render regardless of the number of posts... > > @post.destroy if @post > > -- > Rick DeNatale > > Blog:http://talklikeaduck.denhaven2.com/ > Twitter:http://twitter.com/RickDeNatale > WWR:http://www.workingwithrails.com/person/9021-rick-denatale > LinkedIn:http://www.linkedin.com/in/rickdenatale-- 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.