1

Both partials below are elements of a table and have the same structure. So I wish to merge these two partials first and then render them to my ajax call. Is this possible?

def refreshprojects
  @projects = Project.get(params[:username])
  render :partial => "project.elements.data", :locals => {:projects=>@projects }
  render :partial => "project.shared.elements.data", :locals => {:projects=>@projects_shared }
end
4

2 回答 2

1

考虑到 @projects 和 @shared_projects 是数组,您可以将它们组合成一个数组传递给其中一个部分,而不是单独进行。

渲染 :partial => "project.elements.data", :locals => { :projects=> @projects + @projects_shared }

万一,如果UI的partials有一些不同,你可以在一个视图中用动作的名称调用两者,即,refreshprojects.html.erb从动作中删除这两行。

渲染 :partial => "project.elements.data", :locals => {:projects=>@projects }

渲染 :partial => "project.shared.elements.data", :locals => {:projects=>@projects_shared }

于 2013-08-27T10:35:41.393 回答
1

一种简单的方法是创建另一个视图refreshprojects,然后在其中渲染两个部分。

然后你会渲染refreshprojects到你的 ajax 调用。

于 2013-08-23T20:33:48.023 回答