Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 886655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:06:17+00:00 2026-05-15T13:06:17+00:00

I have a destroy action defined for a particular resource. On completion, it uses

  • 0

I have a destroy action defined for a particular resource. On completion, it uses an rjs file with a visual effect to remove the resource from the page that it is being called from.

My problem is that the destroy action can be called from 2 different templates. And so the visual effect needs to be different, depending on which template it is being called from… Is there a way to do so…?

1: I figure that one way I could do this, is to have a destroy action, and a destroy-variant action, with one template calling the destroy-variant action, and the other calling the normal one… However, I’m pretty sure that that is against the idea of DRY. And to be honest, I’m not entirely sure how to do so either… Will using :method => :delete, :action => :destroy-variant in the URL options work?

2: The other way that seems like a possibility to me, is to find out which page is calling the action, and then pushing out different rjs files as appropriate. But I’ve got absolutely no idea how to differentiate which page is doing the action calling.

3: The final way is just for me to redo the templates/RJS so that the same visual effect can be applied to both templates.

I’d appreciate the advice! 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:06:18+00:00Added an answer on May 15, 2026 at 1:06 pm

    You do not mention the javascript library that you are using. This solution is jquery based. Its quite easy to do what you want using just one action destroy. But i would suggest a different technique to go about it. I find rjs pretty constraining. Go for the jquery taconite plugin. Its all markup rather than… a bunch of javascript mixed with erb which is less appealing to the eyes!

    So now instead of your destroy.rjs you will have a destroy.xml.erb. Before i go into what you need to put in it, lets see what modifications you need to make for your destroy action.

    BEFORE:

       def destroy
            @model = Model.find(params[:id])
            @model.destroy
    
              respond_to do |format|
                format.html { redirect_to :action => :index }
                format.xml
              end
        end
    

    AFTER:

       def destroy
            @model = Model.find(params[:id])
            @model.destroy
            @template = params[:template]
              respond_to do |format|
                format.html { redirect_to :action => :index }
                format.xml
              end
        end
    

    Add a named route in your routes.rb to simplify things:

    map.destroy_using_template 'destroy/:id/:template', :controller => "controller", :action => "destroy"
    

    In your views:

    Add the jquery taconite plugin to the header in your <layout>.html.erb,

    <%= javascript_include_tag "jquery.js", "jquery.taconite.js" %>
    

    In the view for template 1:

    Assuming you use a link to delete.

       <%= link_to "Delete", destroy_using_template_path(:id => "1", :template => "temp1"), :method => :delete, :confirm => "Are you sure you want to delete the record?" %>
    

    and the same for template 2:

    Assuming you use a link to delete.

       <%= link_to "Delete", destroy_using_template_path(:id => "1", :template => "temp2"), :method => :delete, :confirm => "Are you sure you want to delete the record?" %>
    

    Now in your destroy.xml.erb

    <taconite>
        <% if @template=="temp1" %>
          <remove select="#template1" />
        <% elsif @template=="temp2" %>
          <remove select="#template2" />
        <% end %>
    
        <eval>
            //OPTIONAL: Execute some javascript here if you want. You can do most of the DOM modifications using taconite itself.
            alert("HEY!!!");
        </eval>
    </taconite>
    

    Is it not easy now? 🙂

    Remember, while using taconite you have to make sure the code in destroy.xml.erb is XML compliant. Make sure you close any open tags. Read up more on taconite here: http://malsup.com/jquery/taconite/

    Taconite implements all the regular jquery DOM modifiers in markup and a few extra of its own. If you want to switch to javascript you can easily do so by just including that javascript in the eval tag as shown above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following restful structure: My login page uses the session/new action My
I have a rails 3 nested resource defined as follows resources :candidates do collection
I want to have a destroy action that deletes the association in the independent
I have implemented an ajax-based button to add and remove a calendar event from
I have a destroy method within a notecards controller that I am calling from
I have an object which needs to destroy itself. Can it be done? Is
I have a application whereby a user can destroy other users attached to the
I have the following two models: class Parent < ActiveRecord::Base has_one :child, dependent: :destroy
I have just started reading Spring In Action - Third edition and am stuck
In my edit action of my employees_controller I have this line of code: #Employee#edit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.