0

Hello I am trying to retrieve html partials as a single string in an ajax call. I am using public_activity gem. Since I didnt find a way to call the partial(render_activity) from the controller. I tried using the following code, but I am getting an error saying that I can not make more than one render call. Any ideas of how can I achieve what I want?

    @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
Flezcano
  • 1,647
  • 5
  • 22
  • 39
  • 1
    I think you're missing an `end` but might be a copy/paste error. You can only call `render` once like the error says, I'd suggest using your logic to pick the correct partial and pass it the `@new_feeds` collection and then doing the loop inside the appropriate partial itself rather than the controller. – martincarlin87 Jun 26 '14 at 15:20
  • 1
    replace `render` with `render_to_string` – Unixmonkey Jun 26 '14 at 15:31
  • @martincarlin87 yes it was a copy/paste error I could fix it, I appreciate your response, but I think the one from Unixmonkey would be the correct answer, it would be okay if you could put it as answer so I can mark it as the correct one. – Flezcano Jun 26 '14 at 15:53

1 Answers1

2

Replace all occurrances of render with render_to_string

Unixmonkey
  • 18,485
  • 7
  • 55
  • 78