spree_product_groups icon indicating copy to clipboard operation
spree_product_groups copied to clipboard

Products groups permalink translated from russian with letter "Ь"

Open deemytch opened this issue 14 years ago • 0 comments

/cc biow0lf

moved from https://github.com/spree/spree/issues/1232#issuecomment-4442888

spree 1.0, rails 3.1.3, postgresql, linux x64

When creating products group in admin interface, if name is entered on russian with letter "Ь" (soft sign) with have to be translated (why?) to single quote, for ex. "Обувь (shoes) -> Obuv' " this parameter gets passed directly to postgresql in a form

"e_product_groups"  WHERE (permalink LIKE 'Obuv'%') ORDER" etc

that sure throws an error.

In ROR2RU google group user Solenko suppose: ( https://groups.google.com/forum/?fromgroups#!topic/ror2ru/yfGFuZb2B60 )

https://github.com/spree/spree/blob/master/core/lib/spree/core/permalinks.rb#L43

:conditions => "#{field} LIKE '#{permalink_value}%'",

fix

:conditions => ["#{field} LIKE '?'", "#{permalink_value}%"],

BUT I think for the correct translation for permalinks is better to get out from any quotes at all, because of unpredictable manner of appearance of new errors when using quotes and other special symbols in names.

This solved the problem for me:

/app/config/initializers/stringex.rb

class String
  def to_url
    remove_formatting.downcase.gsub(/[ъЪьёЁєЄЇїіІ \'\"\%\.\;\:]+/, '_' ).gsub(/_+/,'_').parameterize
  end
end

deemytch avatar Mar 12 '12 00:03 deemytch