Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

semantic_fields_for and i18n #613

Closed
crystalin opened this Issue · 20 comments

3 participants

@crystalin

I didn't see any other issue about this specific problem:

Here is my form:

= semantic_form_for @paint do |form|
..
=form.input :name
..
=semantic_fields_for :user do |user_form|
...
=user_form.input :name

The label/hint/... for the first input "name" is correct (formtastic.labels.paint....)
but the second input "name" is incorrect. It is using the same as the first one instead of formtastic.labels.user

Other fields inside the semantic_fields_for are treated correctly. Only duplicated ones have issues

@justinfrench
Owner

which version of rails, the i18n gem and formtastic are you running with?

@crystalin

Sorry I forgot to specify:
Rails 3.1.0rc4
Ruby 1.9.2 (Linux)
Formtastic 2.0.0rc3

@justinfrench

@crystalin can you please re-test with formtastic master and rails 3-1-stable? There's been some fixes in both Rails and Formtastic to do with fields_for and semantic_fields_for which may or may not have been related. Also, if it still fails, could you let me know which i18n version you have?

@crystalin

I tried again and I still get the same behavior. The i18n I'm using is 0.6.0
However I think the issue is coming from the scopes inside the i18n.rb

It is actually defined like this:

SCOPES = [
'%{model}.%{nested_model}.%{action}.%{attribute}',
'%{model}.%{action}.%{attribute}',
'%{model}.%{nested_model}.%{attribute}',
'%{model}.%{attribute}',
'%{nested_model}.%{attribute}',
'%{attribute}'
]

I didn't look deep in the code but I guess the order of the scope array define which translation is used.
In the previous one, the
'%{model}.%{attribute}',
is used before the
'%{nested_model}.%{attribute}',

But the good behavior is to take the nested_model before the model if there is one.
Tell me if you think it is logic for you.

@crystalin crystalin closed this
@crystalin crystalin reopened this
@justinfrench

Hi, I think I agree with that change — to try the nested model before the model — but I don't heavily use i18n, so I may be missing something. If someone like @sobrinho could chime in and +1 the change, it should be pretty easy to work up the patch. Start lobbying :)

@sobrinho
Collaborator

@crystalin, this is your real form?

= semantic_form_for @paint do |form|
..
=form.input :name
..
=semantic_fields_for :user do |user_form|
...
=user_form.input :name

If yes, semantic_fields_for is wrong and should be something like:

= semantic_form_for @paint do |form|
..
=form.input :name
..
=form.semantic_fields_for :user do |user_form|
...
=user_form.input :name

Could you post your locale file too?

@crystalin

This is not my real form but the use of semantic_fields_for is the same.
When I remove the "form." before the semantic_fields_for the behavior is correct (the user model attributes are taken instead of the paint model attributes as it was before).

I did form.semantic_fields_for because it was used like this in the example on the formtastic github page. I guess the form.semantic_fields_for is only for nested models... and semantic_fields_for is for independant models.

in my locale file:

formtastic:
  labels:
    user:
      name: "Your name"
    paint:
      name: "Painting"
@sobrinho
Collaborator

I see.

Could you submit a test case?

If changing SCOPES and nothing breaks, that's ok.

@justinfrench

I've had a go at switching this around, but either I'm missing something obvious, or...? I've published to GH-613 branch. If anyone else would care to check my work and offer suggestions or a fix, that'd be great. @sobrinho @crystalin

@justinfrench

Bumping this out to 2.1 since it's a change instead of a concrete bug, and also because I really want to push out a final RC if possible :)

@sobrinho
Collaborator

I will take a look tonight ;)

@justinfrench

@sobrinho — did you?

@sobrinho
Collaborator

@justinfrench @crystalin I can't reproduce the issue.

I've changed the spec to this case but it's working fine here.

@sobrinho
Collaborator

@justinfrench your spec will fail because is wrong.

The issue is related to using semantic_fields_for inside a semantic_form_for without builder.

@crystalin could you submit a test case or a fresh app having this issue?

@justinfrench
Owner

bumped out to 2.1 for now

@crystalin crystalin referenced this issue from a commit in crystalin/formtastic
@crystalin crystalin fix nested object i18n scopes order
add failing spec for issue #613
8da6eae
@crystalin

Sorry for the delay... I changed the scope order, please check if it is correct

@sobrinho
Collaborator

@crystalin, this spec coverage the changed order?

@crystalin

Not sure what you mean but the test is not working if the order is changed

@sobrinho
Collaborator

@crystalin that's question. thanks!

@sobrinho
Collaborator

Fixed on pull request #685

@sobrinho sobrinho closed this
@jcf jcf referenced this issue from a commit in jcf/formtastic
@crystalin crystalin fix nested object i18n scopes order
add failing spec for issue #613
5348bac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.