Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special UTF Characters in format_name and Method Missing #113

Open
fabiode opened this issue Jun 3, 2015 · 0 comments
Open

Special UTF Characters in format_name and Method Missing #113

fabiode opened this issue Jun 3, 2015 · 0 comments

Comments

@fabiode
Copy link

fabiode commented Jun 3, 2015

Hello!

I've been using this gem for a long time, since Spree 1.1. But only now I've encountered a problem with the approach used by the gem using method_missing for establishing the relation between the item (in my case, Spree::Product) and its related items.

The name field is being used in the front-end for dynamic exhibition for relation types, as the following code demonstrates:

<% @relation_types.each do |relation_type| %>
  <% products = @product.send(relation_type.name.parameterize('_')) %>
  <% next if products.empty? %>
  <%= content_tag :h3, relation_type.name %>
  [iteration over each product...]
<% end %>

The problem is that the name have accents, because the current locale is pt-BR.

I thought that this could be solved in two different ways and I would like the opinion of the community:

One of them would be adding an extra field to identify internally the relation, or keeping the name and adding a field like presentation to appear in the front end.

The other way would be changing the format_name method using parameterize instead of downcase, to avoid problems with accents.

Old code

def format_name(name)
  name.to_s.downcase.gsub(' ', '_').pluralize
end

New code

def format_name(name)
  name.to_s.parameterize('_').pluralize
end

I'm not having errors, at least not in development environment, but I guess a method name with accents isn't a good thing...

What you guys think about it?
If you have other solution, I would be glad to read it!

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant