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

Problem with the undecorate option for the new form #2199

Closed
dmfrancisco opened this issue May 15, 2013 · 10 comments
Closed

Problem with the undecorate option for the new form #2199

dmfrancisco opened this issue May 15, 2013 · 10 comments

Comments

@dmfrancisco
Copy link
Contributor

According to the docs, if a resource is decorated, the instance provided to form_for also gets decorated. However, this does not seem to be the case for the new action.

Since passing the decorated instance to forms may cause problems (as explained in the docs), I need to use decorate: false, which internally calls model to return the undecorated instance. It works for edits, but raises an "undefined method 'model' error" for the new action.

module ActiveAdmin
  module ViewHelpers
    module FormHelper
      def active_admin_form_for(resource, options = {}, &block)
        options = Marshal.load( Marshal.dump(options) )
        options[:builder] ||= ActiveAdmin::FormBuilder

        if ! options.fetch(:decorate, true)
          resource = resource.model # <= This line causes the error
        end

        semantic_form_for resource, options, &block
      end
    end
  end
end

Something like:

resource = resource.respond_to?(:model) ? resource.model : resource

Prevents the exception from being raised, but does not fix the problem, which is the instantiated object is not decorated. Thanks for this awesome gem 👍


Note: I already added the fix for Draper +1.1 as explained in the wiki. I'm using AA from master and tested with Draper 1.0.0, 1.1.0 and 1.2.1.

@seanlinsley
Copy link
Contributor

I don't understand why it wouldn't respond to model only on the new action... Any thoughts?

@dmfrancisco
Copy link
Contributor Author

This was a long time ago. At that time, I monkey patched active_admin_form_for like I explained above. Since I'm not using AA anymore, I don't know if this was fixed in the meantime. It seems no one has reported similar issues, so I guess you can close this.

Thank you again for your time, and for the excellent work in pushing this gem forward.
I hope I get to use it again in future projects 👍

@seanlinsley
Copy link
Contributor

Okay, well at any rate thanks for the quick response. I'm trying to clean up the issue tracker so it's easier to manage.

Hopefully you do :]

@aldesantis
Copy link

I'm experiencing this with master on Rails 4. On the "new" page I get an "Undefined method model" error, so for the time being I've just put the following in my model:

def model
  self
end

It'd be nice to see this fixed. :)

@seanlinsley seanlinsley reopened this Oct 24, 2013
@seanlinsley
Copy link
Contributor

Can you try debugging, and finding out what type of object model is trying to be called on in each situation?

@aldesantis
Copy link

I'm sorry, what do you mean exactly by "type of object"?

@seanlinsley
Copy link
Contributor

I meant answering the question: if the resource object isn't a decoration, what is it?

Hmm, I guess there's no point anyway. It seems pretty clear that the 'new' form's object simply isn't decorated. It'd be nice to know for sure though.

@aldesantis
Copy link

Oh, the resource is just an object of the model class.

seanlinsley added a commit that referenced this issue Nov 11, 2013
Don't know what's actually causing the problem, but at least now it
doesn't break
grzegorzblaszczyk added a commit to goodylabs/active_admin that referenced this issue Nov 11, 2013
# By Sean Linsley (153) and others
# Via Sean Linsley (68) and others
* 'master' of github.com:gregbell/active_admin: (293 commits)
  Fix nested resource name in breadcrumbs
  patch activeadmin#2199
  Updated documentation.
  only load the parts of jQuery UI we're actually using
  JS cleanup
  simplify JS folder structure
  Update inline-docs on has-many js
  Fix broken has_many form html and javascript
  Cleanup options that shouldn't render as html attrs
  allow svg icons to be resized
  update CONTRIBUTING.md
  update tests so they work with Devise 3.2
  Update zh-CN.yml
  ensure ActiveRecord is loaded when running tests
  Add missing translations to pt-BR locale
  add formalistic locale
  small docs update
  update 9-batch-actions.md
  update 8-custom-actions.md
  GFM docs update
  ...

Conflicts:
	config/locales/en.yml
	lib/active_admin/form_builder.rb
	lib/active_admin/inputs/filter_string_input.rb
	lib/active_admin/resource/action_items.rb
	spec/unit/filters/filter_form_builder_spec.rb
grzegorzblaszczyk added a commit to goodylabs/active_admin that referenced this issue Nov 11, 2013
…pecific-resources

# By Sean Linsley (153) and others
# Via Sean Linsley (68) and others
* master: (297 commits)
  Fix nested resource name in breadcrumbs
  patch activeadmin#2199
  Updated documentation.
  only load the parts of jQuery UI we're actually using
  JS cleanup
  simplify JS folder structure
  Update inline-docs on has-many js
  Fix broken has_many form html and javascript
  Cleanup options that shouldn't render as html attrs
  allow svg icons to be resized
  update CONTRIBUTING.md
  update tests so they work with Devise 3.2
  Update zh-CN.yml
  ensure ActiveRecord is loaded when running tests
  Add missing translations to pt-BR locale
  add formalistic locale
  small docs update
  update 9-batch-actions.md
  update 8-custom-actions.md
  GFM docs update
  ...

Conflicts:
	lib/active_admin/base_controller/translation.rb
	lib/active_admin/form_builder.rb
@rgalindo33
Copy link

Im having the same issue, is this solved?

@grzegorzblaszczyk
Copy link

Not yet, I will go back to this during the weekend...

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

No branches or pull requests

5 participants