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

Change CSVBuilder to get column name from I18n #2771

Merged
merged 2 commits into from Dec 10, 2013

Conversation

@mateusg
Copy link
Contributor

commented Dec 7, 2013

These changes will make the CSVBuilder try to get the column name through Model.human_attribute_name.

  • If the attribute name is not defined on the locale, the name returned will no longer be "titleized", it will be "humanized".
  • If the value specified to the column method is not a symbol, the builder will print it humanized.
  • Very useful when using locales. :)

Instead of doing this:

csv do
  column("Nome") { |r| r.name }
  column("Idade") { |r| r.age }
  column("Altura") { |r| r.height }
end

I'll do this:

csv do
  column(:name)
  column(:age)
  column(:height)
end

And have my translations defined on the locale file:

pt-BR:
  activerecord:
    attributes:
      person:
        name: Nome
        age: Idade
        height: Altura
mateusg added 2 commits Dec 5, 2013
Change CSVBuilder to get column name from I18n
* Will try to get the column through Model.human_attribute_name.
* If the attribute name is not defined on the locale, the returned name will no longer be "titleized", it will be "humanized".
* If the value specified to the `column` method is not a symbol, it won't get the column name through I18n.
* Very useful when using locales. :)
@coveralls

This comment has been minimized.

Copy link

commented Dec 7, 2013

Coverage Status

Coverage decreased (-0.01%) when pulling 45671c2 on mateusg:csv_column_improvement into 56a255c on gregbell:master.

@seanlinsley

This comment has been minimized.

Copy link
Member

commented Dec 10, 2013

❤️

seanlinsley added a commit that referenced this pull request Dec 10, 2013
Merge pull request #2771 from mateusg/csv_column_improvement
Change CSVBuilder to get column name from I18n

@seanlinsley seanlinsley merged commit 47fda3a into activeadmin:master Dec 10, 2013

1 check passed

default The Travis CI build passed
Details
@mateusg

This comment has been minimized.

Copy link
Contributor Author

commented Dec 10, 2013

YAY! Thanks so much. 😄

/cc @brunohenrique @brennovich

@mateusg mateusg deleted the mateusg:csv_column_improvement branch Dec 10, 2013

@mateusg mateusg restored the mateusg:csv_column_improvement branch Dec 10, 2013

@brennovich

This comment has been minimized.

Copy link
Contributor

commented Dec 11, 2013

Ha! :D


Sent from Mailbox for iPhone

On Tue, Dec 10, 2013 at 7:42 PM, Mateus Gomes notifications@github.com
wrote:

YAY! Thanks so much. 😄

/cc @brunohenrique

Reply to this email directly or view it on GitHub:
#2771 (comment)

@mateusg mateusg deleted the mateusg:csv_column_improvement branch Dec 11, 2013

@sadjow

This comment has been minimized.

Copy link

commented Dec 11, 2013

👍 🆒

@Onumis

This comment has been minimized.

Copy link

commented Mar 28, 2018

I know this is an old one, but is there anyway to skip humanize?

I need a column like this: column 'Input Power (W)' do ... end

And this is being converted into: Input power (w), which is bad because Wattage should be expressed with capital 'W'.

@Onumis

This comment has been minimized.

Copy link

commented Mar 28, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.