-
-
Notifications
You must be signed in to change notification settings - Fork 196
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
Display translations on failed validation #2166
Conversation
I think this works in most cases now, but if the |
81227a0
to
a5a20d3
Compare
e4e1e33
to
4ff39fa
Compare
@@ -60,7 +83,17 @@ def update | |||
def create | |||
I18n.with_locale(I18n.default_locale) do | |||
@category = PublicBodyCategory.new(params[:public_body_category]) | |||
# Build a translation for the default locale as it isn't available |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can just call @category.translation
here which seems to add the default locale in to the translations array:
> category = FactoryGirl.build(:public_body_category)
=> #<PublicBodyCategory id: nil, title: "Example Public Body Category 6", category_tag: "example_tag_6", description: "Example Public body Description 6">
> category.translations
=> []
> category.translation
=> #<PublicBodyCategory::Translation id: nil, public_body_category_id: nil, locale: "en", description: nil, title: nil, created_at: nil, updated_at: nil>
> category.translations
=> [#<PublicBodyCategory::Translation id: nil, public_body_category_id: nil, locale: "en", description: nil, title: nil, created_at: nil, updated_at: nil>]
e3f5521
to
205000f
Compare
Fixes submission of form containing both existing and new translations
Fixes submission of form containing both existing and new translations
205000f
to
a14ce58
Compare
<% @category.ordered_translations.each do |translation| %> | ||
<li> | ||
<a href="#div-locale-<%= translation.locale.to_s %>" data-toggle="tab" > | ||
<%= locale_name(translation.locale.to_s) || _("Default locale") %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably translation.locale.to_s would be a better fallback here than _("Default locale") as this is not necessarily the default locale.
Makes it clearer where the error is. Additionally, don't show the attributes twice - just show the message.
My only question here now is whether it's clear enough what the problem is when the category heading translations in particular fail validation. I've made some commits in #2219 that I think might help. 7929e1b seems like an obvious improvement to the admin interface in general. 533e99b breaks out the error messages and highlights the translation they belong to. ac207f7 fixes the issue that the fields on the default locale aren't getting highlighted because the errors are on the model itself, but probably going back to a pattern like 6b0a79a#diff-e9be0b7887688275035d3346ae523a01R18 is a cleaner fix. |
Ah yep, removed. I'll drop 3b0bfb5, merge the fixups and make a PR against rails-3-develop |
See #2166 |
HOTFIX (Moved from #2154)Merge in to
rails-3-develop
ac907d7 built the translations in the controller rather than the view.
In a request that contains no params for a translation and fails
validation the translation is no longer available to the view. This
commit builds the translations in the case of a failed validation.
Fixes issue brought up in #2140 (comment)
Also fixes #2112, #2113