From 83beb92d4a0899ac94f7528b55ee2816f990bc4e Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 1 Nov 2012 13:19:36 -0400 Subject: [PATCH] refactor and make i18n nicer --- lib/cocoon/formtastic/cocoon_input.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/cocoon/formtastic/cocoon_input.rb b/lib/cocoon/formtastic/cocoon_input.rb index ae2a67a..e9160d7 100644 --- a/lib/cocoon/formtastic/cocoon_input.rb +++ b/lib/cocoon/formtastic/cocoon_input.rb @@ -21,7 +21,7 @@ class CocoonInput def semantic_fields_for builder.semantic_fields_for(method) do |fields| if fields.object - template.render :partial => "#{method.to_s.singularize}_fields", :locals => { :f => fields } + template.render :partial => "#{singular_method}_fields", :locals => { :f => fields } end end end @@ -32,7 +32,7 @@ class CocoonInput def links template.content_tag(:div, :class => 'links') do - template.link_to_add_association template.t('.add'), builder, method, input_html_options + template.link_to_add_association template.t(".add_#{singular_method}"), builder, method, input_html_options end end @@ -43,5 +43,10 @@ class CocoonInput 'data-association-insertion-method' => 'append' ) end + + private + def singular_method + @singular_method ||= method.to_s.singularize + end end