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

WIP: Add dynamic helper instance methods #5

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

joallard
Copy link
Collaborator

I was trying to make a translation page (two languages side by side in a form) and I realized it was not possible to give title_i18n["fr"] to the form helper. So I set out on this great quest to make some dynamic helpers so I could use title_fr when I18n.locale == :en, alas it's not that simple.

So here it is, in all its WIP glory, so you can give your comments and maybe make this a real feature.

@joallard
Copy link
Collaborator Author

Oh hi, globalize-accessors

@joallard joallard force-pushed the dynamic-helpers branch 4 times, most recently from 04817f4 to aa50d9d Compare January 17, 2015 19:52
@joallard joallard force-pushed the dynamic-helpers branch 5 times, most recently from 405ce5e to 8a9dc4f Compare January 25, 2015 20:00
@mjonuschat
Copy link
Owner

I've picked a few of the more generic fixes and updates into the develop branch. A rebase skipping those should get this into a state that could be merged. I like the idea of the dynamic accessor but personally I don't have a use case at the moment. If you think it's stable feel free to merge.

Use in a form: Why not treat the hstore column like any other object/relation and make use of nested form/attributes?

@joallard
Copy link
Collaborator Author

joallard commented Apr 3, 2015

Use in a form: Why not treat the hstore column like any other object/relation and make use of nested form/attributes?

I just poked around, and this is another endeavor entirely. The main reason is that the locale is lower in the hierarchy than the attribute. So, with the stock form helpers, it would mean
fields_for(:title){ |ft| ft.field :en; ft.field :fr } # and so on rather than fields_for(:fr){ |fr| fr.field :title; fr.field :body } as the field key (name) needs to be post[title][en].

If we want to do that that means rolling out our own fields_for_locale helper, nothing impossible, but the hill is steep. I've started writing tests, but I don't know where to begin, as we need to test against ActionView and I'm not really sure how to do that. I agree it would be more elegant though.

@joallard joallard mentioned this pull request Apr 3, 2015
6 tasks
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 this pull request may close these issues.

2 participants