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

Decoration of namespaced models #587

Closed
commel opened this issue Nov 28, 2013 · 7 comments
Closed

Decoration of namespaced models #587

commel opened this issue Nov 28, 2013 · 7 comments

Comments

@commel
Copy link

commel commented Nov 28, 2013

I am using the Version-model of PaperClip (https://github.com/thoughtbot/paperclip) to show historifed data. Loving the decoration draper-gem I want to use it as well. :-)

Everything worked fine, except till the moment when PaperClip decided to move the Version-Model-Class to a Namespace. Now I have to access PaperClip::Version.

How do I tell Draper this?? He keeps missing the model

Draper::UninferrableDecoratorError (Could not infer a decorator for PaperTrail::Version.):
  app/controllers/welcome_controller.rb:18:in `decorate'
  app/controllers/welcome_controller.rb:7:in `index'
@tygriffin
Copy link

I'm having the same issue with the public_activity gem (https://github.com/pokonski/public_activity)

@TylerRick
Copy link

This might be a separate issue (my issue was related to PaperTrail, not PaperClip), but with the issue I was running into, the solution was to change the decorates line in my VersionDecorator from:

  decorates :version

to:

  decorates :'paper_trail/version'

Maybe you just need to add an explicit decorates line somewhere?

@tygriffin
Copy link

Not sure if this is helpful but I ended up adding:
decorates PublicActivity::Activity

Here's a link to my question on SO:
http://stackoverflow.com/questions/20803784/public-activity-gem-decorated-with-draper

@TylerRick
Copy link

Nice. Looks like decorates accepts either a symbol or a class. The symbol is probably just converted to a class...

@commel
Copy link
Author

commel commented Jan 4, 2014

Thank you all for your answers. I had to remove Papertrail in the mean time, but i will try to reproduce the problem and the noted fixes.

@amitpatelx
Copy link

Works well with specifying AR class with namespace

class CampaignDecorator < Draper::Decorator
  decorates Campaign::Campaign
  delegate_all
  def daily_budget_formatted
    number_to_currency(model.daily_budget, precision: 2)
  end
end

UPDATE
Getting following error after deploying on production environment

ActiveRecord::StatementInvalid (PG::Error: ERROR:  relation "campaigns" does not exist
LINE 5:              WHERE a.attrelid = '"campaigns"'::regclass
                                        ^
:             SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                     pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
              FROM pg_attribute a LEFT JOIN pg_attrdef d
                ON a.attrelid = d.adrelid AND a.attnum = d.adnum
             WHERE a.attrelid = '"campaigns"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum
):

@jcasimir
Copy link
Member

Going to remove the idea of automatic inference, so closing this issue.

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