friendly-id

Use Numeric Sequence for Duplicate Slugs [Friendly ID]

本秂侑毒 提交于 2019-12-26 02:45:11
问题 I noticed on the docs it says: Previous versions of FriendlyId appended a numeric sequence to make slugs unique, but this was removed to simplify using FriendlyId in concurrent code. Is there any way to revert back to this format? My model only has name so there aren't any other viable slug candidates and ( time or date wouldn't make sense in this case for slug candidates). How can I change this (current format): car.friendly_id #=> "peugeot-206" car2.friendly_id #=> "peugeot-206-f9f3789a

Use Numeric Sequence for Duplicate Slugs [Friendly ID]

懵懂的女人 提交于 2019-12-26 02:43:06
问题 I noticed on the docs it says: Previous versions of FriendlyId appended a numeric sequence to make slugs unique, but this was removed to simplify using FriendlyId in concurrent code. Is there any way to revert back to this format? My model only has name so there aren't any other viable slug candidates and ( time or date wouldn't make sense in this case for slug candidates). How can I change this (current format): car.friendly_id #=> "peugeot-206" car2.friendly_id #=> "peugeot-206-f9f3789a

“Key (slug)=() already exists” in friendly_id on rails4 app

感情迁移 提交于 2019-12-25 04:40:46
问题 While I'm trying to setup friendly_id to my rails4 project, similarly, I got error after I add "friend" after "friend" to friends table. How can I fix it: PG::UniqueViolation - ERROR: duplicate key value violates unique constraint "index_friends_on_slug" DETAIL: Key (slug)=() already exists. In addition, here are my files the issue may be based on: # app/models/friend.rb: class Friend < ActiveRecord::Base has_many :entries, dependent: :destroy belongs_to :user extend FriendlyId friendly_id

how do I blacklist users slugs with friendly id?

痴心易碎 提交于 2019-12-25 03:13:39
问题 I want to use friendly id so that users can have a nice url. However I want to blacklist certain names such as api or admin or curse words. Where do I load the yaml file to do that? in the model? 回答1: Give the following code a try- class MyModel < ActiveRecord::Base extend FriendlyId excluded_words = ["admin", "api"] friendly_id_config.reserved_words.concat(excluded_words) friendly_id :name, use: [:slugged, :finders] end 回答2: def check_slug_blacklist blacklist = YAML.load_file(Rails.root.join

Rails friendly_id pages still attainable by record id

六眼飞鱼酱① 提交于 2019-12-23 18:53:31
问题 I'am using the friendly_id gem in my rails app, to create nice clean url's. It's working out good, but the page are also attainable by te record id. Example: I've a record with 'name' as slug. This record has 1 for ID. So the page is attainable from 2 url's: domain.com/name and domain.com/1 I want only to use domain.com/name, so I dont want the page to be attainable from domain.com/1. Does anyone know how to accomplish this? 回答1: From the author himself (Google is your friend; this is a top

Friendly_id using value from belongs_to association

走远了吗. 提交于 2019-12-23 09:49:07
问题 I have the following models: class User < ActiveRecord::Base extend FriendlyId friendly_id :first_name, :use => :slugged has_one :professor after_create :create_professor def create_professor self.professor = Professor.create end end class Professor < ActiveRecord::Base extend FriendlyId friendly_id :first_name, :use => :slugged belongs_to :user def first_name user.first_name end end At the time that create_professor is called and therefore the execution passes to the Professor model ( self

Friendly_Id and Reserved Words — How can i replace the reserved word?

本秂侑毒 提交于 2019-12-23 09:47:41
问题 Here is an example of what causes the error: ruby-1.9.2-p290 :004 > Post.new(title: "new").save! (0.3ms) BEGIN post Load (0.3ms) SELECT `posts`.* FROM `posts` WHERE (`slug` = 'new' OR `slug` LIKE 'new--%') ORDER BY LENGTH(`slug`) DESC, `slug` DESC LIMIT 1 (0.3ms) SELECT 1 FROM `posts` WHERE `posts`.`lsi_post_id` = BINARY '' LIMIT 1 (0.1ms) ROLLBACK ActiveRecord::RecordInvalid: Validation failed: Friendly is reserved I would like to put something in the Post model that maybe replaces a new

Rails globalize + friendly id

别来无恙 提交于 2019-12-23 02:53:48
问题 I have a problem with globalize and friendly_id. The site has 2 languages Ru and En. Gem friendly_id, globalize and friendly_id-globalize configured and work. If I change the language from Russian to English, all is well: http://127.0.0.1:3000/ru/o-saite -> http://127.0.0.1:3000/en/about-site But when I change from English to Russian going wrong redirection: http://127.0.0.1:3000/en/about-site -> http://127.0.0.1:3000/ru/about-site page model: class Page < ActiveRecord::Base validates :title,

friendly_id and real id

白昼怎懂夜的黑 提交于 2019-12-21 20:28:25
问题 Is there any way to get the real id column from a model that is modified with friendly_id? I don`t want to make another db query for it, in performance reasons. 回答1: Broadly speaking friendly_id modifies to_param and find methods. Next should work: @affiche = Affiche.find(params[:id]) # params[:id] is a slug @id = @affiche.id 回答2: Have you tried attributes["id"] ? e.g: Model.first.attributes["id"] 来源: https://stackoverflow.com/questions/7944908/friendly-id-and-real-id

Rails Friendly_Id on Heroku, Heroku not updating slugs

試著忘記壹切 提交于 2019-12-20 02:26:06
问题 I've set up the friendly_id gem, following along to the RailsCasts Screencast on it. Locally this works brilliantly, I installed it, ran through User.find_each(&:save) which successfully updated the slug field on each of the existing users and all was fine. I have now pushed this to Heroku, and although it works fine for any new members that are added, Heroku isn't updating the user slug for me for already existing Users. Running heroku run console and then User.find_each(&:save) just does