I'm trying to render the integrated 404 page in rails as an exception. I tried this but still getting the routing error page:
posts_controller.rb
def destroy
if current_user.username == @post.email
@post.destroy
respond_to do |format|
format.html { redirect_to posts_url }
format.json { head :no_content }
end
else
not_found
end
application_controller.rb
def not_found
raise ActionController::RoutingError.new('Not Found')
end
routes.rb
Booklist::Application.routes.draw do
get "pages/faq"
get "pages/about"
devise_for :users
resources :posts
root 'posts#index'
end
view:
<% if current_user.username == post.email %>
<font color="red">This is your post! Feel free to edit or delete it. -> </font>
<%= link_to 'Edit', edit_post_path(post) %>
<%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %>
<% end %>
No route matches [GET] "/posts/15/destroy"