Best RJS process for what I'm trying to do

I just wanted to ping this off the list to get some advice since I’m
now pulling my hair out. Thanks in advance for taking any time to look
at this. It’s much appreciated. Now, my problem is my RJS is working
but it’s not inserting how I want it to insert. I have a partial I’m
rendering in my view that looks like this:

    id="meal_names">

    <% @meal_names.each do |item| -%>

  • <%= item.name %> <%= link_to "delete", { :controller => 'meal_names', :action => 'destroy', :id => item.id}, :confirm => "are you sure you want to delete #{ item.name}?" %>
  • do |item| -%>
  • <%= item.name %> <%= link_to "delete", { :controller => 'meal_names', :action => 'destroy', :id => item.id}, :confirm => "are you sure you want to delete #{ item.name}?" %>
  • <%= item.name %> <%= link_to "delete", { :controller => 'meal_names', :action => 'destroy', :id => item.id}, :confirm => "are you sure you want to delete #{ item.name}?" %>
  • <% end %>end %>

and this does give me a list of names but when i submit a new name, it
gets added to the list as just

  • #{@name.name}
  • so it doesn’t have the formatting or the delete button like the other
    items. Whenm I refresh the page, then it looks proper. Here’s my
    controller add method:

    def add

    @name = MealName.create( params[:meal_name] )
    @meal_names = MealName.find(:all)
    @meal_names << @name
    render :update do |page|
    page.insert_html :bottom, ‘meal_names’, "

  • #{@name.name}
  • "
    page.visual_effect :highlight, ‘meal_names’, :duration => 3
    end
    

    end

    I thought I could get around this by doing a @meal_names << @name and
    that didn’t work. I’m thinking I’m just not doing this properly. Help!

    Your RJS template is doing exactly what you told it to.
    If you want all the other link stuff, you have to add it.
    I suggest creating a partial that does all the formatting you want for
    each item and then insert that partial to the end of meal_names.

    On Sunday, April 09, 2006, at 3:32 PM, Curtis E. wrote:

    item.id}, :confirm => “are you sure you want to delete #{ item.name}?”

    @meal_names << @name


    Rails mailing list
    [email protected]
    http://lists.rubyonrails.org/mailman/listinfo/rails

    _Kevin