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

Error for models containing at least one concern with included block #5

Open
movstox opened this issue Mar 19, 2016 · 2 comments
Open

Comments

@movstox
Copy link

movstox commented Mar 19, 2016

Hi and thanks for this gem

If I have a model

class Account < ActiveRecord::Base
  include Avatarify
end

that includes a concern

module Meritify
  extend ActiveSupport::Concern

  included do
    mount_uploader :avatar, AvatarUploader
  end

  def thumb_avatar_url
    avatar.thumb.url
  end

  def normal_avatar_url
    avatar.normal.url
  end
end

and i run

SchemaBuilder::Writer.new.write

via rails console

I'm getting this

ActiveSupport::Concern::MultipleIncludedBlocks: Cannot define multiple 'included' blocks for a Concern
from /home/oivai/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.0/lib/active_support/concern.rb:126:in `included'

If I exclude concern from model, everything works just fine. Would you point me to the right direction? Is there a solution?

@schorsch
Copy link
Member

I suppose there is a problem with your own module inclusion, as we dont use any ActiveSupport::Concern in here.

The writer just looks at your models and tries to figure out their names and available fields in model_as_hash:

find models:
https://github.com/salesking/json_schema_builder/blob/master/lib/schema_builder/writer.rb#L121
Introspect:
https://github.com/salesking/json_schema_builder/blob/master/lib/schema_builder/writer.rb#L36

By looking at the error you seem to use the 'included do' block twice within the same module.
Maybe you have a chance to prevent the usage of AR::Concern(and its hard-to-figure-out-errors-magic) by using the plain 'includes InstanceMethods, extend ClassMethods' scheme.

@movstox
Copy link
Author

movstox commented Mar 21, 2016

Thanks, I'll give it a try!

On 21.03.2016 at 10:54 GMT Georg Leciejewski wrote:

I suppose there is a problem with your own module inclusion, as we dont use any ActiveSupport::Concern in here.

The writer just looks at your models and tries to figure out their names and available fields in model_as_hash:

find models:
https://github.com/salesking/json_schema_builder/blob/master/lib/schema_builder/writer.rb#L121
Introspect:
https://github.com/salesking/json_schema_builder/blob/master/lib/schema_builder/writer.rb#L36

By looking at the error you seem to use the 'included do' block twice within the same module.
Maybe you have a chance to prevent the usage of AR::Concern(and its hard-to-figure-out-errors-magic) by using the plain 'includes InstanceMethods, extend ClassMethods' scheme.


You are receiving this because you authored the thread.
Reply to this email directly or #5 (comment)<>

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

2 participants