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 3492028
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:42:30+00:00 2026-05-18T11:42:30+00:00

This is a Rails 3 project using jQuery 1.4.4. I have an index action

  • 0

This is a Rails 3 project using jQuery 1.4.4.

I have an index action that displays a list of resources in a table, complete with a “Destroy” link like you’d get from a scaffold:

<tr id="showcase_item_<%= showcase_item.id %>" class="<%= cycle(' alt','') %>">
  <td><%= displayable.identifier %></td>
  <td><%= escape_javascript(link_to 'Remove', showcase_item, :confirm => 'Remove this item from your Showcase?', :method => :delete, :remote => true) %></td>
</tr>

On that index view I also have a little form that does an AJAX “create” for the resource, and I am using Javascript to append the resource to the table in my create.js.erb:

$("#showcase tr:last").after("<tr id=\"showcase_item_<%= @showcase_item.id %>\" class=\"<%= cycle(' alt','') %>\"> \
<% displayable = @showcase_item.displayable %> \
<td><%= displayable.identifier %></td> \
<td><%= link_to 'Remove', @showcase_item, :confirm => 'Remove this item from your Showcase?', :method => :delete, :remote => true %></td></tr>")

That is brittle, hideous, and not DRY. How else can I do that?

What is the Rails Way of doing this?

I appreciate any help or guidance you can provide!

  • 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-18T11:42:31+00:00Added an answer on May 18, 2026 at 11:42 am

    The trick is to extract the table row into a partial (as it is being used twice). Then in your js view, simple render the partial. For example, here is a small snippet to get you started:

    # _object.html.erb
    <%= content_tag_for(:tr, @object, :class => cycle('odd','even')) do %>
     <td><%=h @object.name %></td>
     <td><%= link_to 'Remove', object_path(@object), :method => :delete %></td>
    <% end %>
    
    # index.html.erb
    <table id="objects">
      <%= render :partial => @objects %>
    </table>
    
    # create.js.rjs
    page << "$('#objects').append('#{escape_javascript(render :partial => @object)}');"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started considering using the HTML 5 api for a Rails/JQuery project,
I have a rails model that looks something like this: class Recipe < ActiveRecord::Base
I have a Rails 2.3.5 project that uses the localization features of Rails. I
Hey Guys. I have got a problem on using the jquery auto-complete plugin.my problem
I am using jquery date picker in rails project, I want to disable the
I followed this tutorial on configuring the Rails plugin ExceptionNotifier. I know that I
Well this is incredibly frustrating. After being nagged by Rails that I need to
I have a three-level multi-nested form in Rails. The setup is like this: Projects
First as a note I am using this plugin in a Rails app. Ok
I created a Ruby-on-Rails project using NetBean 6.8, which operates as expected on port

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.