Saturday, December 5, 2009

[Rails] Struggling to delete posts... Can you help?

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@googlegroups.com.
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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate