Search code examples
ruby-on-railsrubyinternationalizationupdate-attributesfriendly-id

Using Friendly ID and i18n with update_attributes causes overwrite


Using: - Rails 3.0.3 - Friendly_id 4.0.0 Beta 11 - Windows - i18n (0.6.0, 0.5.0) according to "gem list"

Set-up: I have a multilingual website about calculations using Swedish and English as languages. I am using friendly_id to create seo-friendly url's.

In my mysql-table I have columns "slug", "slug_se" and "slug_en". I am not sure if I need to use the "slug"-column, it is identical with "slug_en".

Problem: While using "update_attributes" it overwrites "slug_se" with "slug" (which by default is in English). Thus, the value in "slug" is written in "slug_se".

Trouble shooting: - I have Googled this issue and only found one (unanswered) forum thread on Google Forum (http://groups.google.com/group/friendly_id/browse_thread/thread/154f4a5024e23418) that was left unanswered. - I have tried to find alternatives to update_attributes, I could go through mysql but that really wouldn't be neat.

Questions: - Do I need to use the "slug"-column at all? - Is there an alternative to update_attributes that does not try to update the id as well? - Can you see anything wrong in what I am doing that is causing the problem?

Code: Model:

  extend FriendlyId
  friendly_id :name, :use => :slugged, :use => I18n

Solution

  • I'm the author of FriendlyId. You'd probably have better luck asking this question in the Github issues for the project, I just happened to see this by chance.

    The i18n module is still pretty new, so sorry for the instability and thanks for the feedback. :)

    In answer to your question about the slug column, no you should not have it at all: just slug_en and slug_se. This was a change made on September 4th:

    https://github.com/norman/friendly_id/commit/54536464132ac8f72c96e8bda203c337f9d56aa0

    So try removing that column. If your problems persist please feel free to post a bug report on Github and I'll look at it as soon as I can.

    In the mean time I will try adding a test to try to reproduce the issue you describe, and if I can reproduce it, I'll definitely fix it.