8

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]:

B Seven
  • 44,484
  • 66
  • 240
  • 385

2 Answers2

17
<%= link_to "Delete", item_path(:id => item.id, :foo => 1), :confirm => 'Are you sure?', :method => :delete %>
jdl
  • 17,702
  • 4
  • 51
  • 54
  • 1
    for rails 5, the :confirm needs to put inside data key. ```link_to "Destroy", item_path(id: item.id, foo: 1), data: { confirm: 'Are you sure?' }, method: :delete``` – V-SHY Jan 11 '19 at 05:32
3

I think you are looking for:

item_path(item, :foo => 1)

It should appear in your params

Candide
  • 30,469
  • 8
  • 53
  • 60