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

Using helpers inside builder #8

Closed
dimoreira opened this issue Jan 27, 2016 · 3 comments · Fixed by #11
Closed

Using helpers inside builder #8

dimoreira opened this issue Jan 27, 2016 · 3 comments · Fixed by #11

Comments

@dimoreira
Copy link

How can one use a Rails helper inside the builder class?
I already tried to include the helper but this didn't work for me.

My example:

class UserCreditsCSVBuilder < Julia::Builder
    include ActionView::Helpers::NumberHelper

    column "Value" do |c|
        number_to_currency c.amount
    end
end
@beechnut
Copy link

While I would have expected include to be the right inheritance method, I tried extend and it worked:

class DevelopmentCsv < Julia::Builder
  extend ActionView::Helpers::DateHelper

  column "Value" do |c|
    time_ago_in_words c.created_at
  end
end

DevelopmentCsv.build([Development.first])
#=> "Value\nabout 20 hours\n"

I assume this has something to do with the DSL-style syntax, since other objects in my app (like presenters) which use standard method definition, include the functionality correctly using include.

class EditPresenter < Burgundy::Item
  include ActionView::Helpers::DateHelper
  def time_ago
    "#{time_ago_in_words(created_at)} ago"
  end
end

@stevenbarragan
Copy link
Owner

@dimoreira extend will do the job for now (thanks @beechnut), but you're right, it should be include, I'll keep this issue open in order to fix it.

@dimoreira
Copy link
Author

@beechnut @stevenbarragan Great guys. I will try extend for now. And keep an eye on this thread to see updates on code semantics.

Thanks

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

Successfully merging a pull request may close this issue.

3 participants