Skip to content

Commit 4bf00af

Browse files
authored
Merge pull request #237 from Muskworker/i180-update-g11n-accessors
Update accessors when adding/updating a language
2 parents 3728397 + bc91875 commit 4bf00af

4 files changed

Lines changed: 16 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* [#202] Fixed an issue with adding to the lexeme form when assigned to multiple dictionaries
1111
* [#169] Short lists now only show the most acceptable headwords
1212
* [#234] Fixed an issue with listing additional loci for potential constructions
13+
* [#180] Fixed an issue that forced a restart to use newly-added languages
1314

1415
## Since 0.4.1
1516
* [#89] Lexeme form now arranges etymology horizontally instead of by nesting

app/controllers/languages_controller.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def create
4747

4848
respond_to do |format|
4949
if @language.save
50+
update_accessors
51+
5052
flash[:notice] = t('languages.new.success')
5153
format.html { redirect_to(@language) }
5254
format.xml { render :xml => @language, :status => :created, :location => @language }
@@ -64,6 +66,8 @@ def update
6466

6567
respond_to do |format|
6668
if @language.update_attributes(params[:language])
69+
update_accessors
70+
6771
flash[:notice] = t('languages.edit.success')
6872
format.html { redirect_to(@language) }
6973
format.xml { head :ok }
@@ -94,4 +98,13 @@ def matching
9498
format.js { render :partial => "autocomplete" }
9599
end
96100
end
101+
102+
private
103+
104+
# Update accessors for models that have accessors defined
105+
def update_accessors
106+
ActiveRecord::Base.descendants.each do |c|
107+
c.globalize_accessors(locales: Language.defined_language_codes) if c.respond_to?(:globalize_locales)
108+
end
109+
end
97110
end

app/models/language.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def language
109109

110110
# Return an array of the language codes defined in the system.
111111
def self.defined_language_codes
112-
@defined_language_codes ||= all.collect(&:iso_639_code)
112+
all.collect(&:iso_639_code)
113113
end
114114

115115
# Given a string +query+,

app/views/languages/new.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<%= form_for @language, { method: :post, action: 'create', html: {:class => "yform"}} do |f| %>
44
<%= # @action = "Create"
5-
render(:partial => "longform", :for_url => "/#{I18n.locale}/languages", locals: {language_form: f} })
5+
render(:partial => "longform", :for_url => "/#{I18n.locale}/languages", locals: {language_form: f})
66
%>
77

88

0 commit comments

Comments
 (0)