Rails,如何组合多个模型属性以使用 permalink_fu 创建唯一的永久链接?
Permalink_fu 可以组合 2 个或更多模型属性来创建唯一的永久链接吗?
假设我有一个业务模型,该模型包含:名称、:地址、:电话、:城市、:州、:国家等属性。
设置了永久链接,
现在我在这个模型中仅为 :name has_permalink :name
所以我会得到“/biz/name”。不过,如果该企业在该城市有超过 1 个地点,我想将企业名称、城市和增量数字合并起来。
例如,我想使用:
“/biz/joes-coffee-shack-chicago”作为永久链接
,或者如果是多个位置业务
“/biz/starbucks-chicago-92”,
这可以使用当前的 permalink_fu 插件或某些分叉吗的 permalink_fu?或者这需要对 permalink_fu 插件进行一些修改?
Can Permalink_fu combine 2 or more model attributes to create a unique permalink?
Let's say I have a Business Model, this model contains :name, :address, :phone, :city, :state, :country etc. attributes.
Right now I have permalink set up in this model only for :name
has_permalink :name
So I would get "/biz/name". However I would like to combine the Business name, city, and a incremental number if there are more than 1 location in the city for that business.
For example I would like to use:
"/biz/joes-coffee-shack-chicago" for the permalink
or if a multple location business
"/biz/starbucks-chicago-92"
Is this possible with the current permalink_fu plugin or some fork of permalink_fu? Or will this require some modification to the permalink_fu plugin?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将属性设置为数组:
它们将自动通过
-
连接。如果已经存在带有该永久链接的记录,Permalink_fu 还会自动添加后缀。You can set the attributes as an array:
They will be automatically joined by
-
. Permalink_fu also automatically adds a suffix if there's already a record with that permalink.将虚拟属性添加到您的
业务
模型中。Add a virtual attribute to your
Business
model.