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 <[email protected]> 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 <[email protected]> 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 <[email protected]>
> > 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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.


Reply via email to