轨道控制器中的多个渲染

时间:2014-06-26 15:13:27

标签: ruby-on-rails public-activity

您好我试图在ajax调用中将html partials检索为单个字符串。我正在使用public_activity gem。因为我没有找到从控制器调用部分(render_activity)的方法。我尝试使用以下代码,但我收到一个错误,说我不能进行多个渲染调用。关于如何实现我想要的任何想法?

    @new_feeds.each_with_index do |new_feed|
      if new_feed.trackable_type == "CompanyDocument" 
        if new_feed.key == "company_document.create"
          html = render partial: 'public_activity/company_document/create', :locals => { :activity => new_feed }
        elsif new_feed.key == "company_document.update"
          html = render partial: 'public_activity/company_document/update', :locals => { :activity => new_feed }
        end
      elsif new_feed.trackable_type == "CompanyVideo" 
        if new_feed.key == "company_video.create"
          html = render partial: 'public_activity/company_video/create', :locals => { :activity => new_feed }
        elsif new_feed.key == "company_video.update"
          html = render partial: 'public_activity/company_video/update', :locals => { :activity => new_feed }
        end
      end
   end

1 个答案:

答案 0 :(得分:2)

将所有render替换为render_to_string