Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined method safe_append= for nil #3916

Closed
seanlinsley opened this issue Apr 27, 2015 · 9 comments
Closed

Undefined method safe_append= for nil #3916

seanlinsley opened this issue Apr 27, 2015 · 9 comments

Comments

@seanlinsley
Copy link
Contributor

I just upgraded an app from using Active Admin b794f4b to b3a9f4b. A form that looks like this:

<%= active_admin_form_for [:admin, @property] do |f| %>
  <% f.inputs do %>
    <% f.input :name %>
    <% f.input :address %>

    <%= f.form_buffers.pop %>
    <% f.form_buffers << ''.html_safe %>

    <h3>Junk</h3>
    <table>
      <!-- ... -->
    </table>

    <% f.has_many :images do |i| %>
      <% i.input :image, as: :file, hint: i.object.image.url ? image_tag(i.object.image.url) : '' %>
    <% end %>

    <%= f.form_buffers.last %>
  <% end %>
<% end %>

Started raising this error:

NoMethodError - undefined method `safe_append=' for nil:NilClass:
  app/views/admin/properties/_form.html.erb:1:in `block in _app_views_admin_properties__form_html_erb__4480795312609525413_70285274106140'
   activeadmin-b3a9f4b3e405/lib/active_admin/views/components/active_admin_form.rb:35:in `build'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:28:in `block in build_tag'
  arbre (1.0.3) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:26:in `build_tag'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:14:in `active_admin_form_for'
   activeadmin-b3a9f4b3e405/lib/active_admin/view_helpers/form_helper.rb:7:in `block in active_admin_form_for'
  arbre (1.0.3) lib/arbre/context.rb:45:in `initialize'
   activeadmin-b3a9f4b3e405/lib/active_admin/view_helpers/form_helper.rb:6:in `active_admin_form_for'
  app/views/admin/properties/_form.html.erb:1:in `_app_views_admin_properties__form_html_erb__4480795312609525413_70285274106140'
  actionview (4.1.6) lib/action_view/template.rb:145:in `block in render'
  activesupport (4.1.6) lib/active_support/notifications.rb:161:in `instrument'
  actionview (4.1.6) lib/action_view/template.rb:339:in `instrument'
  actionview (4.1.6) lib/action_view/template.rb:143:in `render'

Which is confusing since #3486 was supposed to raise an error to make the upgrade path clear. Any idea what the issue might be? Note that I haven't yet tried upgrading Rails to 4.2, or Active Admin past b3a9f4b.

Rewriting the form to use Arbre fixed the issue, but I should've seen a better error message.

@timoschilling
Copy link
Member

I'm wondering about where is safe_append= coming from, both b794f4b and b3a9f4b, don't have this method and even arbre don't have this method.
safe_append= ia a Rails method (source).

@seanlinsley
Copy link
Contributor Author

Yeah. The stack trace doesn't help, but I'm guessing it's being called from here.

@timoschilling
Copy link
Member

Does this error still happens after you removed form_buffers and use arbre?

@seanlinsley
Copy link
Contributor Author

The form's contents are not causing the error. I was able to get that exception with just this:

<%= active_admin_form_for [:admin, @property] do |f| %>
<% end %>

That is, merely having a do / end block caused the error.

@aennchen
Copy link

For me, using semantic_form_for and specifying the builder explictly fixed the error

<%= semantic_form_for resource, builder: ActiveAdmin::FormBuilder do |f| %>

@francirp
Copy link

@aennchen solution worked for me with the following slight modification to point to the correct url:

<%= semantic_form_for [:admin, resource], builder: ActiveAdmin::FormBuilder do |trip_builder| %>

tf added a commit to tf/pageflow that referenced this issue Mar 3, 2016
Using `semantic_form_for` directly causes deprecation warnings since
Formtastic requires more custom configuration
now. `active_admin_form_for` is not usable in erb templates at the
moment (see activeadmin/activeadmin#3916).
tf added a commit to tf/pageflow that referenced this issue Mar 3, 2016
Using `semantic_form_for` directly causes deprecation warnings since
Formtastic requires more custom configuration
now. `active_admin_form_for` is not usable in erb templates at the
moment (see activeadmin/activeadmin#3916).
tf added a commit to tf/pageflow that referenced this issue Mar 10, 2016
Using `semantic_form_for` directly causes deprecation warnings since
Formtastic requires more custom configuration
now. `active_admin_form_for` is not usable in erb templates at the
moment (see activeadmin/activeadmin#3916).
aviav pushed a commit to aviav/pageflow that referenced this issue Jun 14, 2016
Using `semantic_form_for` directly causes deprecation warnings since
Formtastic requires more custom configuration
now. `active_admin_form_for` is not usable in erb templates at the
moment (see activeadmin/activeadmin#3916).
aviav pushed a commit to aviav/pageflow that referenced this issue Jun 14, 2016
Using `semantic_form_for` directly causes deprecation warnings since
Formtastic requires more custom configuration
now. `active_admin_form_for` is not usable in erb templates at the
moment (see activeadmin/activeadmin#3916).
aviav pushed a commit to aviav/pageflow that referenced this issue Jun 15, 2016
Using `semantic_form_for` directly causes deprecation warnings since
Formtastic requires more custom configuration
now. `active_admin_form_for` is not usable in erb templates at the
moment (see activeadmin/activeadmin#3916).
aviav pushed a commit to aviav/pageflow that referenced this issue Jun 15, 2016
Using `semantic_form_for` directly causes deprecation warnings since
Formtastic requires more custom configuration
now. `active_admin_form_for` is not usable in erb templates at the
moment (see activeadmin/activeadmin#3916).
tf added a commit to tf/pageflow that referenced this issue Jun 22, 2016
Using `semantic_form_for` directly causes deprecation warnings since
Formtastic requires more custom configuration
now. `active_admin_form_for` is not usable in erb templates at the
moment (see activeadmin/activeadmin#3916).
tf added a commit to tf/pageflow that referenced this issue Jun 22, 2016
Using `semantic_form_for` directly causes deprecation warnings since
Formtastic requires more custom configuration
now. `active_admin_form_for` is not usable in erb templates at the
moment (see activeadmin/activeadmin#3916).
aviav pushed a commit to aviav/pageflow that referenced this issue Jun 27, 2016
Using `semantic_form_for` directly causes deprecation warnings since
Formtastic requires more custom configuration
now. `active_admin_form_for` is not usable in erb templates at the
moment (see activeadmin/activeadmin#3916).
@varyonic varyonic added the forms label Feb 8, 2017
@varyonic
Copy link
Contributor

I'm closing this as won't fix. active_admin_form_for is no longer supported from an ERB partial but a workaround is provided above, though the recommended action is to convert to Arbre, which is now supported inside the form. Yes, the error was not friendly but this issue has seen little activity past couple of years. Added link here from upgrading page on wiki.

@vfonic
Copy link
Contributor

vfonic commented Jan 29, 2020

For anyone coming here, active_admin_form_for seems to be working for ERB partials, if you use a single <%= %> tag, across the whole form, like this:

<%=
  active_admin_form_for [:admin, resource] do |f|
    f.semantic_errors *f.object.errors.keys
    f.inputs do
      f.input :url
      f.input :community_id
    end
    f.actions do
      f.action :submit
    end
  end
%>

Please also note the [:admin, resource].

@adrian-BOS
Copy link

For anyone coming here, active_admin_form_for seems to be working for ERB partials, if you use a single <%= %> tag, across the whole form, like this:

this worked for me thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants