diff --git a/app/views/render_async/_render_async.html.erb b/app/views/render_async/_render_async.html.erb index 38d0e8b..9cb045e 100644 --- a/app/views/render_async/_render_async.html.erb +++ b/app/views/render_async/_render_async.html.erb @@ -5,7 +5,7 @@ <%= placeholder %> > -<% content_for :render_async do %> +<% content_for local_assigns.has_key?(:content_for_name) ? content_for_name : :render_async do %> <%= javascript_tag html_options do %> <% if RenderAsync.configuration.jquery %> <%= render partial: 'render_async/request_jquery', diff --git a/lib/render_async/view_helper.rb b/lib/render_async/view_helper.rb index ed0ea8c..0818f38 100644 --- a/lib/render_async/view_helper.rb +++ b/lib/render_async/view_helper.rb @@ -31,7 +31,8 @@ def render_async(path, options = {}, &placeholder) **request_options(options), **error_handling_options(options), retry_count: retry_count, - **polling_options(options) + **polling_options(options), + **content_for_options(options) end private @@ -58,6 +59,12 @@ def polling_options(options) toggle: options[:toggle] } end + def content_for_options(options) + { + content_for_name: options[:content_for_name] || :render_async + } + end + private def generate_container_id diff --git a/spec/render_async/view_helper_spec.rb b/spec/render_async/view_helper_spec.rb index 186eeed..135a347 100644 --- a/spec/render_async/view_helper_spec.rb +++ b/spec/render_async/view_helper_spec.rb @@ -56,7 +56,8 @@ error_message: nil, error_event_name: nil, retry_count: 0, - interval: nil + interval: nil, + content_for_name: :render_async } ) @@ -89,7 +90,8 @@ error_message: nil, error_event_name: nil, retry_count: 0, - interval: nil + interval: nil, + content_for_name: :render_async } ) @@ -116,7 +118,8 @@ error_message: nil, error_event_name: nil, retry_count: 0, - interval: nil + interval: nil, + content_for_name: :render_async } ) @@ -143,7 +146,8 @@ error_message: nil, error_event_name: nil, retry_count: 0, - interval: nil + interval: nil, + content_for_name: :render_async } ) @@ -170,7 +174,8 @@ error_message: nil, error_event_name: nil, retry_count: 0, - interval: nil + interval: nil, + content_for_name: :render_async } ) @@ -197,7 +202,8 @@ error_message: nil, error_event_name: nil, retry_count: 0, - interval: nil + interval: nil, + content_for_name: :render_async } ) @@ -224,7 +230,8 @@ error_message: nil, error_event_name: nil, retry_count: 0, - interval: nil + interval: nil, + content_for_name: :render_async } ) @@ -251,7 +258,8 @@ error_message: nil, error_event_name: nil, retry_count: 0, - interval: nil + interval: nil, + content_for_name: :render_async } ) @@ -284,7 +292,8 @@ error_message: nil, error_event_name: nil, retry_count: 0, - interval: nil + interval: nil, + content_for_name: :render_async } ) @@ -311,7 +320,8 @@ error_message: nil, error_event_name: nil, retry_count: 0, - interval: nil + interval: nil, + content_for_name: :render_async } ) @@ -343,7 +353,8 @@ error_message: nil, error_event_name: nil, retry_count: 5, - interval: nil + interval: nil, + content_for_name: :render_async } ) @@ -373,7 +384,8 @@ error_message: nil, error_event_name: nil, retry_count: 0, - interval: 5000 + interval: 5000, + content_for_name: :render_async } ) @@ -383,5 +395,37 @@ ) end end + + context "content_for_name is given" do + it "renders render_async partial with proper parameters" do + expect(helper).to receive(:render).with( + "render_async/render_async", + { + html_element_name: "div", + container_id: /render_async_/, + container_class: nil, + path: "users", + html_options: {}, + event_name: nil, + toggle: nil, + placeholder: nil, + method: 'GET', + data: nil, + headers: {}, + error_message: nil, + error_event_name: nil, + retry_count: 0, + interval: nil, + content_for_name: :render_async_other_name + } + ) + + helper.render_async( + "users", + content_for_name: :render_async_other_name + ) + end + end + end end