aboutsummaryrefslogtreecommitdiffstats
path: root/app/helpers/application_helper.rb
diff options
context:
space:
mode:
authorDavid Cabo <david@calibea.com>2011-10-13 00:29:51 +0200
committerDavid Cabo <david@calibea.com>2011-10-13 00:29:51 +0200
commitc8983b923e4dc7db9ba22156daaddd94d2b5ed4d (patch)
tree7741c3655fe5e3cbc90dd20a4626ac7acc1bf6b0 /app/helpers/application_helper.rb
parenta29b3aaf0ae77af49d38813b62dddcb6889c1ebe (diff)
parente13127a8ebc8bf8379d92f778af5a2bb6931d80c (diff)
Merge branch 'release/0.4'0.4
Diffstat (limited to 'app/helpers/application_helper.rb')
-rw-r--r--app/helpers/application_helper.rb19
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