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

Setup is run after "has_widgets" #127

Open
jokklan opened this issue Oct 1, 2013 · 1 comment
Open

Setup is run after "has_widgets" #127

jokklan opened this issue Oct 1, 2013 · 1 comment

Comments

@jokklan
Copy link

jokklan commented Oct 1, 2013

I have a setup method in almost all my widgets that sets a instance variable that should be presented by the widget. I use the after_initialize callback method to call setup. Often however do i want to pass this instance to a child widget, but the setup method is called after has_widgets so it's not set yet. Is their a way to change this order?

Example:

class UsageWidget < Apotomo:Widget
  after_initialize :setup

  has_widgets do |root|
    self << widget("usage/graph", :graph,
      usage: @usage) # doesn't work, @usage is not set yet
  end

  def display
    render
  end

  private

  def setup(widget)
    @user = options[:user]
    @organization = options[:organization]
    @usage = UsagePresenter.new(@user, @organization, view_context)
  end

end
@blahutka
Copy link

+1

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