Take the 2-minute tour ×

I'm using Paperclip to store images for records called 'Expense' - images are of receipts for the expense.

Everything works find, but when I go to edit an expense, I want to have a link to delete the image associated with that expense, so in my expense_controller, I have:

def delete_receipt_img
  @expense = Expense.find(params[:id])


  redirect_to edit_expense_path(params[:id])

I generate the view of the edit expense page with a partial that displays the delete link only if an image is associated with the expense:

<% if @expense.id.nil? || !@expense.receipt_img.file? %>
    <%= f.label :attach_receipt %><br/>
    <%= f.file_field :receipt_img %>
<% else %>
    <%= image_tag @expense.receipt_img.url %>
    <%= link_to "Delete Receipt", 
                :method => :put %>
<% end %>

In my routes file, I followed an example from the Rails routing guide, and created the link like this:

resources :expenses do
  member do
   put 'delete_receipt_img'

When I go to the the edit expense page, I see the "delete receipt" link is generated as such:

<a href="http://localhost:3000/expenses/1/delete_receipt_img" data-method="put" rel="nofollow">Delete Receipt</a>

So it looks like everything is fine, but when I click the link, I get a routing error:

Routing Error

No route matches [GET] "/expenses/1/delete_receipt_img"

Try running rake routes for more information on available routes.

I can't figure out where this GET request is coming from! Ideas?

share|improve this question
According to the doc for link_to, adding :method => :put will generate a form (which is required in order to execute a non-GET request). That doesn't appear to be happening. Check here: api.rubyonrails.org/classes/ActionView/Helpers/… –  Tom Harrison Jr Dec 4 '12 at 2:08
I have read that. I even checked to see if I had Javascript disabled (under which condition, it'll default to GET), but it's not disabled. –  Shinigami Dec 4 '12 at 21:32

Your Answer



Browse other questions tagged or ask your own question.