views:

62

answers:

1

I modify my RoR application to calling a create.js.rjs after created an item. I want to reload a specify div in my page after I create an item, how can I do that?

When my div have a ruby object like this:

<div id="categoryList">
    <% @categories.each do |category| %>
    <%= content_tag(:dt, category.name, :class => "menu-table")%><%= link_to 'X', category, :confirm => 'Are you sure?', :method => :delete %>
    <%category.products.each do |product| %>
        <%= content_tag(:dd, product.title, :class => "menu-table")%><%= link_to 'X', product, :confirm => 'Are you sure?', :method => :delete %>
        <% end %>
        <% end %>
</div>

how can I pass the ruby object to this then reload the specific page again?

+2  A: 

You can target it using an id tag.

for example in your view

<div id="my-div"> Replace this content </div>

Then in your rjs file

page.replace_html("my-div", "Your updated content");

When you are using Ajax, I would recommend giving each div or element that you plan on interacting with a unique id so that you can target them from Javascript.

Good luck! If you need anything else just let me know,

Thanks,

Kent

ewakened