Am trying to insert a link to delete via ajax in my RJS template. Can one use content_tag and link_to_remote like this in a RJS template? a = content_tag(''a'', link_to_remote("Delete", :update => "categories", :url => {:action => "delete", :name => category.name})) -Thanks. -- Posted via http://www.ruby-forum.com/.
if @category && @category.errors.empty? a = content_tag(''a'', link_to_remote("Delete", :update => "categories", :url => {:action => "delete", :name => @category.name})) li = content_tag( ''li'', @category.name, "id" => @category.name ) page.insert_html :bottom, ''categories'', li page.visual_effect :highlight, ''categories'', :duration => 3 end Basically I am trying to do the above and have this as the output <li>some category [<a ...>Delete</a>] 1. Can one use content_tag and link_to_remote like this in a RJS template? 2. How do i add the "a" tag created above in the DOM? I think I have to use a nested content_tag like li = content_tag( ''li'', @category.name content_tag("a", a), "id" => @category.name ) But the above line seems to be incorrect .. seems like i cannot do something like the third parameter above Thanks. -- Posted via http://www.ruby-forum.com/.
Putting it out here so that someone can point out if this is the optimal way to achieve the result above : if @category && @category.errors.empty? a = content_tag(''span'',link_to_remote("Delete", :update => "categories", :url => {:action => "delete", :name => @category.name})) temp = @category.name + " [" + a + "] " li = content_tag( ''li'', temp, "id" => @category.name ) page.insert_html :bottom, ''categories'', li page.visual_effect :highlight, ''categories'', :duration => 3 end it works .. instead of: <li>some category [<a ...>Delete</a>]</li> I get: <li>some category <span>[<a ...>Delete</a>]</span></li> Would still be interested in seeing a solution that produces the result without the span. -- Posted via http://www.ruby-forum.com/.