dannymcc
dannymcc

Reputation: 3814

Add a value to a delete link in Rails?

I currently have the following link_to in my Rails application:

<%= link_to 'Remove this Person', @person, :confirm => 'Are you sure?', :method => :delete, :class => 'important', :class => "minimal important" %>

I would like to add the person's name in place of the "this person" for the link.

I don't appear to be able to do:

<%= link_to 'Remove <%= @person.name %>', @person, :confirm => 'Are you sure?', :method => :delete, :class => 'important', :class => "minimal important" %>

I have seen this example online:

<%= link_to(@profile) do %>
    <strong><%= @profile.name %></strong> -- <span>Check it out!</span>
  <% end %>
  # => <a href="/profiles/1">
         <strong>David</strong> -- <span>Check it out!</span>
       </a>

Any ideas on how to convert that into a delete link, with the confirmation box?

Upvotes: 0

Views: 119

Answers (1)

krunal shah
krunal shah

Reputation: 16339

Try this.

<%= link_to "Remove #{@person.name}", @person, :confirm => 'Are you sure?', :method => :delete, :class => 'important', :class => "minimal important" %>

Upvotes: 2

Related Questions