Rails:Friendly_id 使用名称而不是 slug 作为 id
使用:Rails 3.0.3 Friendly_id: 4.0.0.beta11
我已经创建了一个完全工作的应用程序开发版本,其中一切正常,包括Friendly_id url:s,如domain.com/cars/mitsubishi
现在我正在 Heroku 上部署该应用程序,但我不能由于某种原因让Friendly_id 工作。
问题:当我将其部署在 Heroku 上时,它给我的“名称”为Friendly_id,而不是 slug_en 或 slug_se。 Calculation.first.Friendly_id 给出例如“我是一个计算”,而不是“我是一个计算”,后者是 slug_en 的内容。
模型(计算)
extend FriendlyId
friendly_id :name, :use => :slugged, :use => I18n
迁移(计算):
t.string :slug_en
t.string :slug_se
Migratiotion2:
add_index :calculations, :slug_en, :unique => true
add_index :calculations, :slug_se, :unique => true
问题是我需要将(heroku db:push)我的本地数据库推送到Heroku(因为它充满了数据),因此我不确定我可以信任多少迁徙。据我了解,它们会被 db:push 覆盖。
现在,这并不重要,因为它在本地运行良好。如果我使用 I18n.locale = :se 它会给我 slug_se 作为 id 和 slug_en 作为 :en。
值得一提的是,Heroku 使用 postgre,而我在本地使用 mysql,如果这很重要的话。
我的问题:
- 如果我将名称属性设置为Friendly_id而不是slug_en或slug_se,通常会出现什么问题
- 我在此处提交的代码有什么问题吗?
- postgre / mysql 差异会导致此问题吗?
- 这是我的 Heroku 安装上未创建索引的问题吗?
谢谢!
Using: Rails 3.0.3
Friendly_id: 4.0.0.beta11
I have create a fully working development version of an application where I got everything working, including friendly_id url:s like domain.com/cars/mitsubishi
Now I am deploying the application on Heroku but I can't get the friendly_id to work for some reason.
Problem: When I deploy it on Heroku it gives me "name" as friendly_id and not slug_en or slug_se. Calculation.first.friendly_id gives for example "I am a calculation" as opposed to "i-am-a-calculation" which would be the content of slug_en.
Model (Calculation)
extend FriendlyId
friendly_id :name, :use => :slugged, :use => I18n
Migration (Calculation):
t.string :slug_en
t.string :slug_se
Migratiotion2:
add_index :calculations, :slug_en, :unique => true
add_index :calculations, :slug_se, :unique => true
The problem is that I need to push (heroku db:push) my local database to Heroku (since it is filled with data) and thus I am not sure how much I can trust the migrations. As far as I understand, they get overwritten with db:push.
Now, that shouldn't really matter since it works fine locally. If I use I18n.locale = :se it will give me the slug_se as id and slug_en for :en.
Worth to mention is that Heroku uses postgre and I use mysql locally, if that matters.
My questions:
- What could typically be the problem if I get the name-attribute as friendly_id instead of the slug_en or slug_se
- Is there anything wrong with the code that I have submitted here?
- Could postgre / mysql-differences cause this?
- Is it a matter of indices not being created on my Heroku installation?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题似乎出在我将文件上传到 Heroku 时。 Heroku 使用Friendly_id 4.0.0.beta8,它是 4.0.0.beta11 中第一个出现 slug_en/slug_se 的地方(如果我理解正确的话)。
因此,问题仍然没有得到解决,而是变成了一种完全不同类型的问题,与这张票中提出的问题并不真正相关。
仅供参考:新问题是“为什么要将Friendly_id 的版本更改为早期版本”。
It seemed like the problem lies in that when I upload the files to Heroku. Heroku uses friendly_id 4.0.0.beta8 and it is first in 4.0.0.beta11 where the slug_en/slug_se appears (if I understand it correctly).
So, the problem is still not fixed but changed to quite a different type of problem that is not really related to the question posed in this ticket.
FYI: The new problem is "Why is the version of friendly_id being changed to an earlier version".