I am trying to delete a message using the following code:
<%= link_to 'Destroy', post, :method => :delete, :onclick => "return confirm('Are you sure you want to delete this post?')" %>
which doesn't work ... it just redirects me back to the post (posts/:id}
however, if I use the following code, it works
<%= button_to 'Destroy', post, method: :delete, :onclick => "return confirm('Are you sure you want to delete this post?')" %>
can link_to behave like button_to in this case?
EDIT: destroy controller function
def destroy @post = Post.find(params[:id]) @post.destroy respond_to do |format| format.html { redirect_to posts_url } format.json { head :no_content } end end
log when i click destroy button:
Started GET "/posts/14" for 127.0.0.1 at 2012-10-21 15:38:28 +0300 Processing by PostsController
routes:
devise_for :users resources :users resources :posts match '/about' => 'about#index'
fxuser
source share