diff options
Diffstat (limited to 'app/helpers/application_helper.rb')
-rw-r--r-- | app/helpers/application_helper.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ec56566a9..a0f16dfaf 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -94,5 +94,24 @@ module ApplicationHelper block.call end end + # (unfortunately) ugly way of getting id of generated form element + # ids + # see http://chrisblunt.com/2009/10/12/rails-getting-the-id-of-form-fields-inside-a-fields_for-block/ + def sanitized_object_name(object_name) + object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/,"_").sub(/_$/,"") + end + + def sanitized_method_name(method_name) + method_name.sub(/\?$/, "") + end + + def form_tag_id(object_name, method_name, locale=nil) + if locale.nil? + return "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}" + else + return "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}__#{locale.to_s}" + end + end + end |