{"id":310,"date":"2009-03-14T16:03:23","date_gmt":"2009-03-14T21:03:23","guid":{"rendered":"http:\/\/mikeconley.ca\/blog\/?p=310"},"modified":"2023-12-20T16:25:21","modified_gmt":"2023-12-20T21:25:21","slug":"rendering-multiple-partials-with-ruby-on-rails","status":"publish","type":"post","link":"https:\/\/mikeconley.ca\/blog\/2009\/03\/14\/rendering-multiple-partials-with-ruby-on-rails\/","title":{"rendered":"Rendering Multiple Partials with Ruby on Rails"},"content":{"rendered":"<p>So, as we speak, I&#8217;m going through a bit of the code that I&#8217;ve submitted for the OLM project, and I&#8217;ve begun refactoring.<\/p>\n<p>While doing this, I ran into an interesting problem:\u00a0 I want to use Rails&#8217; remote_function to update two sections of the page with an AJAX call.\u00a0 For a while, this stumped me, because you can really only have one render call within a controller method, like this:<\/p>\n<pre>render :partial =&gt; \"footer\"<\/pre>\n<p>But I was determined to render two.\u00a0 So here&#8217;s what I ended up doing:<\/p>\n<p>On the client side, I&#8217;ve got this in my view&#8230;<\/p>\n<pre>&lt;%= remote_function (:url =&gt;{ :action =&gt; \"codeviewer\", :id =&gt; @assignment.id, :uid =&gt; @uid },\r\n                   :with =&gt; \"'fid='+fid\", :after =&gt; \"$('working').hide();\")%&gt;<\/pre>\n<p>And in the Controller, in the &#8220;codeviewer&#8221; method, I do this: <\/p>\n<pre>render :update do |page|\r\n    page.replace_html 'codeviewer', :partial =&gt; 'codeviewer', :locals =&gt;\r\n        { :uid =&gt; params[:uid], :filetext =&gt; filetext, :annots =&gt; annots}\r\n      #Also update the annotation_summary_list\r\n    page.replace_html 'annotation_summary_list', :partial =&gt; 'annotation_summary', :locals =&gt; {:annots =&gt; annots, :fid =&gt; @fid}\r\nend<\/pre>\n<p>This will render my two partials in the DOM elements with ID&#8217;s &#8216;codeviewer&#8217; and &#8216;annotation_summary_list&#8217;, respectively.<\/p>\n<p>Nice.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, as we speak, I&#8217;m going through a bit of the code that I&#8217;ve submitted for the OLM project, and I&#8217;ve begun refactoring. While doing this, I ran into an interesting problem:\u00a0 I want to use Rails&#8217; remote_function to update two sections of the page with an AJAX call.\u00a0 For a while, this stumped me, [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[162,79],"tags":[160,161,158,157,159,86,87],"class_list":["post-310","post","type-post","status-publish","format-standard","hentry","category-ruby-on-rails-technology","category-technology","tag-multiple","tag-multiple-partials","tag-partials","tag-rails","tag-rendering","tag-ruby","tag-ruby-on-rails"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/prmTy-50","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/posts\/310","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/comments?post=310"}],"version-history":[{"count":3,"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/posts\/310\/revisions"}],"predecessor-version":[{"id":3255,"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/posts\/310\/revisions\/3255"}],"wp:attachment":[{"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/media?parent=310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/categories?post=310"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/tags?post=310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}