Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I am assuming you are using <code>resources :photo</code>.<br> The action should be <code>destroy</code> and not <code>delete</code>, as per the <a href="http://guides.rubyonrails.org/routing.html#crud-verbs-and-actions" rel="nofollow">Rais Guide</a>.<br> The seven default actions are: <code>index, new, create, show, edit, update and destroy</code></p> <pre><code> def destroy @photo = current_user.photos.find(params[:id]) @photo.destroy redirect_to photos_path end </code></pre> <p>You can also see the <a href="http://guides.rubyonrails.org/routing.html#inspecting-and-testing-routes" rel="nofollow">available routes</a> by:</p> <pre><code>rake routes </code></pre> <p><strong>EDIT</strong></p> <p>The problem is here: <code>:only =&gt; [:index, :show, :new, :create]</code>, which is saying to rails: do not create <code>destroy</code>, <code>edit</code> or <code>update</code> routes.</p> <p>To solve the problem, you can add destroy to it <code>:only =&gt; [:index, :show, :new, :create, :destroy]</code> or use <code>:except</code> instead: <code>:except =&gt; [:edit, :update]</code></p> <p>If you don't want to limitate the resources:</p> <pre><code>resources :photos do post 'upload', :on =&gt; :collection end </code></pre> <p><strong>EDIT 2</strong> - I don't really understand why you are trying to use <code>delete</code> instead of <code>destroy</code>, However, if you have a good reason for it:</p> <pre><code>resources :photos :only =&gt; [:index, :show, :new, :create] do post 'upload', :on =&gt; :collection get 'delete', :on =&gt; :member end </code></pre> <p>In this way you will have the <code>delete_photo_path</code>, which can be used in your show view:</p> <pre><code>&lt;%= link_to 'Delete', delete_photo_path(@photo) %&gt; </code></pre> <p>Finally, the action delete should looks like:</p> <pre><code>def delete @photo = Photo.find(params[:id]) @photo.destroy redirect_to photos_path end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload