Skip to content

Products groups permalink translated from russian with letter "Ь" #1

@deemytch

Description

@deemytch

/cc biow0lf

moved from spree/spree#1232 (comment)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions