0

I am very new to Ruby and Rails and I am trying to make a modification to a page that is generating the Show, Edit and Delete links for the records using activescaffold. The issue I have is that the page that I am looking at has the links being generated automatically by activescaffold and I need to change only the Delete link to go to another page where I can display a message that will say, You are deleting "option blah blah", Are you sure you want to do that? and give them a cancel and ok button.

My issue at this time is I am not sure where to look for where the links are being generated and hence I am not able to target the new page.

Here is the code that is creating the links

<table cellpadding="0" cellspacing="0">
<tr>
<td class="indicator-container">
  <%= loading_indicator_tag(:action => :record, :id => record.id) %>
</td>
<% active_scaffold_config.action_links.each :record do |link| -%>
  <% next if controller.respond_to? link.security_method and !controller.send(link.security_method) -%>
  <td>
  <% if record.class.statused? and record.disabled? -%>
      <%= link.action.to_sym == :enable ? render_action_link(link, url_options) : "" -%>
  <% else -%>
    <%= (record.authorized_for?(:action => link.crud_type) and link.action.to_sym != :enable) ? render_action_link(link, url_options) : "" -%>
  <% end -%>  
  </td>
<% end -%>

Thank you for any help on this matter.

richcfml
  • 39
  • 1
  • 7

1 Answers1

0

This answer is not specific to ActiveScaffold, but in Rails 3.2, the destroy link is generated as

<%= link_to 'Destroy', foo_instance, method: :delete, data: { confirm: 'Are you sure?' } %>

which results in the link having a data-confirm attribute, which does what it sounds like you want. Can you add this to your ActiveScaffold view?

UPDATE (Rails 2):

The data-confirm attribute is supported by jQuery (instead of, or in addition to prototype), so if you're using jQuery in a Rails 2 app, it might "just work". Otherwise, it's possible that you could just add javascript directly on the link you want to confirm. The url_options parameter for render_action_link looks juicy -- maybe it will accept arbitrary html attributes (as Rails link_to does), e.g.

 url_options = { :onclick => 'return confirm("Are you sure?")` } 
 render_action_link(link, url_options)
Tom Harrison
  • 13,533
  • 3
  • 49
  • 77
  • Thank you for your prompt response and it is my mistake but I am not working in Rails 3.2, the application that I am working with was actually made in Rails 2.3.12 and the code I pasted is the partial that is called on the main page where the links and the list of options is being displayed. I am not sure if the link_to will work on this version of Rails and to be honest I have been working with rails for just a very short period of time. Thank you for all the help. – richcfml Nov 28 '12 at 17:25