将友好 ID 和 i18n 与 update_attributes 一起使用会导致覆盖
使用: - 轨道 3.0.3 -Friendly_id 4.0.0 测试版 11 - 窗户 - i18n (0.6.0, 0.5.0) 根据“gem list”
设置: 我有一个使用瑞典语和英语作为语言进行计算的多语言网站。我正在使用Friendly_id 来创建SEO 友好的URL。
在我的 mysql 表中,我有“slug”、“slug_se”和“slug_en”列。我不确定是否需要使用“slug”列,它与“slug_en”相同。
问题: 使用“update_attributes”时,它会用“slug”覆盖“slug_se”(默认情况下为英语)。因此,“slug”中的值被写入“slug_se”中。
故障排除: - 我在 Google 上搜索了这个问题,只在 Google 论坛 (http://groups.google.com/group/friend_id/browse_thread/thread/154f4a5024e23418) 上找到了一个(未答复的)论坛主题,该主题尚未得到答复。 - 我试图找到 update_attributes 的替代方案,我可以通过 mysql,但这确实不太好。
问题: - 我是否需要使用“slug”列? - 是否有 update_attributes 的替代方案,也不会尝试更新 id? - 你能看出我所做的事情有什么问题导致了这个问题吗?
代码: 模型:
extend FriendlyId
friendly_id :name, :use => :slugged, :use => I18n
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我是FriendlyId 的作者。你可能会更幸运地在该项目的 Github 问题中提出这个问题,我只是偶然看到这个问题。
i18n 模块仍然很新,因此对不稳定感到抱歉并感谢您的反馈。 :)
在回答您关于 slug 列的问题时,不,您根本不应该拥有它:只需 slug_en 和 slug_se 。这是 9 月 4 日进行的更改:
https://github.com/norman/Friendly_id/commit/54536464132ac8f72c96e8bda203c337f9d56aa0
所以尝试删除该列。如果您的问题仍然存在,请随时在 Github 上发布错误报告,我会尽快查看。
同时,我将尝试添加一个测试来尝试重现您描述的问题,如果我可以重现它,我一定会修复它。
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.
诺曼,谢谢。我删除了 slug 列,但这并没有解决问题。看起来默认的 slug 会覆盖 update_attributes 处的 slug_se 。
这是来自日志:
检查@36mCACHE,它(正确地)使用slug_se = procent,然后向下两行@36mCalculation LOAD它进行选择,其中slug_se =百分比(百分比是slug_en)。
我会在 Git 上写一份错误报告!
编辑:我做了一些可能有帮助的调试:
我在模型中使用此方法调用更新:
该提升创建了这个:
参数是:
我做了一个提升计算。Friendly_id.inspect,它显示了“procent”。
Norman, thanks. I removed the slug column but this didn't solve it though. It seems like the default slug overwrites the slug_se at update_attributes.
This is from the log:
Check out @36mCACHE where it (correctly) uses slug_se = procent and then two rows down @36mCalculation LOAD it makes a select where slug_se = percentage (percentage being slug_en).
I will write a bug report at Git!
Edit: I did some more debugging that might be of assistance:
I call an update with this method in the model:
That raise creates this:
the parameters are:
I did a raise calculation.friendly_id.inspect and it showed "procent".