Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add parameter to delete link?

I have a standard delete link, and want to add a parameter to it:

<%= link_to "Delete", item, :confirm => 'Are you sure?', :method => :delete, :foo => 1 %>

The parameter shows up in the html a tag, but does not make to the server. I get "undefined local variable or method `foo'".

Here is how I am accessing it in the controller:

def destroy
    puts "params[:foo]:" + params[:foo].to_s 
    .
    .
    .
    redirect_to edit_bar_path(params[:foo])

The output is params[:foo]:

like image 472
B Seven Avatar asked Jun 18 '11 01:06

B Seven


People also ask

Can Delete have query parameters?

There's nothing wrong with using DELETE on a collection and filtering by query parameters.

How to remove params from URL in Js?

Just pass in the param you want to remove from the URL and the original URL value, and the function will strip it out for you. To use it, simply do something like this: var originalURL = "http://yourewebsite.com?id=10&color_id=1"; var alteredURL = removeParam("color_id", originalURL);


2 Answers

<%= link_to "Delete", item_path(:id => item.id, :foo => 1), :confirm => 'Are you sure?', :method => :delete %>
like image 76
jdl Avatar answered Nov 06 '22 01:11

jdl


I think you are looking for:

item_path(item, :foo => 1)

It should appear in your params

like image 3
Candide Avatar answered Nov 06 '22 02:11

Candide