Tag: friendly id

使用Rails 5,我怎样才能使FriendlyId附加一个 – “count + 1”来复制slus而不是UUID?

显然,FriendlyId已经改变了以前默认的方法,即附加一个数字序列来复制slug(这就是我想要的)现在使用UUID: Previous versions of FriendlyId appended a numeric sequence to make slugs unique, but this was removed to simplify using FriendlyId in concurrent code. 此function不是我现在感兴趣的东西,而是更喜欢使用原始方法来生成更清晰的URL。 我发现了一个类似的问题,其中有人提供了以下代码来覆盖friendlyId normalize_friendly_id方法以获得我之后的function,但使用它会导致错误( wrong number of arguments (given 1, expected 0) ): def normalize_friendly_id count = self.count “name = #{name}” super + “-” + count if name > 0 end 我试图将其“转换”成一个友好的“候选人”,但我真的不知道我在做什么,以下不起作用。 […]

NoMethodError at / undefined方法`name’代表nil:NilClass

我已经尝试了很多解决方案,并提出了一个好的但仍然出错。 我正在编辑我的整个问题。 我正在尝试使用friendly_id gem创建友好URL。 在我的项目中,第一个用户需要使用设计注册。 设计会将一些信息传递给配置文件模型 模型/ user.rb delegate :age, :city, :region, :country, to: :profile 我想让user.name成为Friendly_id候选者。 我在我的个人资料模型中尝试过以下代码: – class Profile < ActiveRecord::Base extend FriendlyId friendly_id :user_name , use: :slugged def user_name user.name end 但它给出了错误 NoMethodError at / undefined方法`name’代表nil:NilClass 现在提交用户表单后。 请提供可能的解决方案和解释。 我的User.rb看起来像 require ‘open-uri’ class User (name) do joins(:profile).where(‘lower(name) LIKE ?’, “%#{name.downcase}%”) end delegate :age, :city, […]