Forum: Ruby on Rails Best RJS process for what I'm trying to do...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4c4c46ad9a5e4df8ba4ea8353e19c2fd?d=identicon&s=25 Curtis Edmond (Guest)
on 2006-04-09 23:34
(Received via mailing list)
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:


<ul id="meal_names">id="meal_names">

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

<li><b><%= item.name %></b> <font size="0"><%= link_to "delete", {
:controller => 'meal_names', :action => 'destroy', :id => item.id},
:confirm => "are you sure you want to delete #{ item.name}?"
%></font></li>do |item| -%>

<li><b><%= item.name %></b> <font size="0"><%= link_to "delete", {
:controller => 'meal_names', :action => 'destroy', :id => item.id},
:confirm => "are you sure you want to delete #{ item.name}?"
%></font></li><li><b><%= item.name %></b> <font size="0"><%= link_to
"delete", { :controller => 'meal_names', :action => 'destroy', :id =>
item.id}, :confirm => "are you sure you want to delete #{ item.name}?"
%></font></li>

<% end %>end %>

</ul>



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

<li> #{@name.name}   </li>

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', "<li> #{@name.name}   </li>"
   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!
5d15c6821f3c3054c04b85471824ba7c?d=identicon&s=25 Kevin Olbrich (Guest)
on 2006-04-10 00:26
(Received via mailing list)
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 Edmond wrote:
>
>item.id}, :confirm => "are you sure you want to delete #{ item.name}?"
>
>  @meal_names << @name
>_______________________________________________
>Rails mailing list
>Rails@lists.rubyonrails.org
>http://lists.rubyonrails.org/mailman/listinfo/rails


_Kevin
This topic is locked and can not be replied to.