views:

80

answers:

1

I am trying to create a tabbed interface using the prototype helper method "replace_html." I have three different partials I am working with. The first one is the 'main tab' and it is loaded automatically like so:

<div id = "grid">
    <% things_today = things.find_things_today %>
    <%= render :partial => "/todaything", :collection => things_today, :as =>:thing %>
</div>

...which works fine. Similarly, I have a _tomorrowthing partial which would replace the content in the 'grid' div like so:

<%things_tomorrow = things.find_things_tomorrow%>
<%= link_to_function('Tomorrow',nil, :id=>'tab') do |page|
  page.replace_html 'grid' , :partial => '/tomorrowthing',:collection => things_tomorrow, :as => :thing
end %>

If I click on this tab nothing happens at all. Using firebug, the only errors I find are a missing ) after argument list which is contained in the Element.update block where the link_to_function is called. What am I doing wrong?

A: 

Hey Jack i try to reproduce the same but i can't i never used link_to_function before but Following code may help to achieve the same you want

<%= link_to_remote "Today Thing", :url=>{:action=>"things", :id=>'today'}%> 
<%= link_to_remote "Tomorrow Thing", :url=>{:action=>"things", :id=>'tomorrow'}%> 

<div id = "grid">
    <% @things = things.find_things_today %>
    <%= render :partial => "/todaything", :collection => @things %>
</div>

in controller

def things
@things= (params[:id]=="today")? things.find_things_today : things.find_things_tomorrow


render :update do |page|
 page.replace_html 'grid',  :partial => (params[:id]=="today")? "/todaything" : '/tomorrowthing'  , :objects=> @things
end
Salil
Okay yes, that works great. But is there any other way? Does anyone know why the prototype helper wasn't working? I'll leave this open for a few more days. Thank you Salil.
Jack