kiwiupover
kiwiupover

Reputation: 1780

Rails 3.1 Ajax 500 Error

I'm getting a 500 error when I try to use ajax to delete a post. It works just fine without using ajax.

In the view I have this to delete a post

<%= link_to 'Destroy', post, confirm: 'Are you sure?', method: :delete,:remote => true, :class => 'delete_post' %>

In the controller I have this for the Destroy method.

def destroy
@post = Post.find(params[:id])
@post.destroy

respond_to do |format|
  format.html { redirect_to posts_url }
  format.js
end
end

In the browser I get a 500 error.

Run Rails 3.1 Ruby 1.9.2-p290 and brand new 3.1 app

What am I doing wrong

Upvotes: 1

Views: 704

Answers (1)

Steve Davis
Steve Davis

Reputation: 1009

It's probably a missing template error. If you don't specify any parameters in a format statement, Rails looks for and loads a file named action . format . template language (destroy.js.erb).

Try something like this:

format.js { render text: "Object successfully destroyed", status: :destroyed }

Upvotes: 1

Related Questions