我正在尝试使用原型辅助方法“replace_html”创建一个标签式界面。我有三个与我合作的不同部分。第一个是'主标签',它会自动加载:
<div id = "grid">
<% things_today = things.find_things_today %>
<%= render :partial => "/todaything", :collection => things_today, :as =>:thing %>
</div>
......工作正常。同样,我有一个_tomorrowthing partial会替换'grid'div中的内容,如下所示:
<%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 %>
如果我点击此标签,则根本没有任何事情发生。使用firebug,我发现的唯一错误是missing ) after argument list
,它包含在调用link_to_function的Element.update块中。我做错了什么?
答案 0 :(得分:0)
嘿杰克我尝试重现相同但我不能以前从未使用过link_to_function但是 以下代码可能有助于实现您想要的相同
<%= 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>
控制器中的
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