Skip to content

Commit

Permalink
Change the way of assigning template variables
Browse files Browse the repository at this point in the history
`ActionView::Base#assign` method removes all previous view variable assignments from ActionView::Base `assigns` hash if there are any.

For example:

    template.assigns # => {page_title: "Awesome Title"}
    template.assign(has_many_block: true) # this will clear the `assigns` hash
    template.assigns # => {has_many_block: true}

This commit changes the way of assigning template variables, to avoid previously assigned values loss:

    template.assigns[:has_many_block] = true
  • Loading branch information
Anton Chumakov committed Sep 27, 2016
1 parent f892683 commit 765f8ea
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/active_admin/form_builder.rb
Expand Up @@ -62,7 +62,7 @@ def has_many(assoc, options = {}, &block)
template.concat has_many_actions(has_many_form, builder_options, "".html_safe)
end

template.assign(has_many_block: true)
template.assigns[:has_many_block] = true
contents = without_wrapper { inputs(options, &form_block) } || "".html_safe

if builder_options[:new_record]
Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/views/components/active_admin_form.rb
Expand Up @@ -43,7 +43,7 @@ def build(resource, options = {}, &block)

def inputs(*args, &block)
if block_given?
form_builder.template.assign(has_many_block: true)
form_builder.template.assigns[:has_many_block] = true
end
if block_given? && block.arity == 0
wrapped_block = proc do
Expand Down

0 comments on commit 765f8ea

Please sign in to comment.