Questions tagged [friendly-id]
FriendlyId is the "Swiss Army bulldozer" of slugging and permalink plugins for Ruby on Rails. It allows you to create pretty URL's and work with human-friendly strings as if they were numeric ids for Active Record models.
495
questions
0
votes
2
answers
45
views
Why is my custom slug method skipping it's code?
I am trying to perform the following actions to alter my urls:
parse instances of "an-" from my url
remove a prefix of "the-" from my url if present.
class BlogPost < ...
0
votes
1
answer
92
views
How to add the name of a blog post's category to route url with Rails 7
I have been trying to add the name of the BlogCategory that a BlogPost belongs to in a URL such as this:
sitename.com/blog/category-name/blog-post-title
At the very least, I want this to render for ...
0
votes
0
answers
29
views
Rails: Use strings like "1", "1.2", "1.2.1", and "1.2.1a" as ID values of a model
I have a tree-like structure of the Web Content Accessibility Guidelines (WCAG) with my model wcag_elements.
class WcagElement < ApplicationRecord
acts_as_tree order: :position
def to_param
...
0
votes
0
answers
69
views
ActiveRecord::RecordNotFound Issue in Rails
I see the above issue while accessing active admin show page for model "campaign". This might be due to friendly_id gem, but I'm unable to identify what exactly the issue is.
My campaign.rb ...
0
votes
0
answers
90
views
Rails + Friendly Id query for ids and slugs in joined model
I need to be able to search items by both id and slug.
I am using the gem friendly-id with rails to handle slugs.
I have a request where I am looking for "Products" that are linked to ...
0
votes
1
answer
44
views
When using the friendly_id gem - can you ignore certain routes like /about /contact?
I'm using the friendly_id gem in a Rails application, to be able to view organisations at site.com/organisation-name
The problem is that I have a few static pages like "About" and "...
0
votes
2
answers
158
views
Rails friendly_id gem not working with link_to helpers?
I’ve set the friendly_id gem up, and generated slugs for my model.
The slugs are all shown in my DB column, and if I run Event.friendly.find('my-event-name') in the console, it works perfectly.
My URL’...
1
vote
1
answer
97
views
Modified ID in URLs to avoid guessing different integer IDs in Rails
I am asking almost to the same question asked here: Encrypted ID in URLs
Only I don't necessarily need the ID encrypted, I use a random string code. And I have tried a similar solution to what João ...
1
vote
2
answers
98
views
My normalize_friendly_id override is never called
I am very new to friendly_id and it matches my need to provide friendly URLs 👍
I have a Group model (i.e. a group of users) for which I generate a unique code upon creation. FYI, this code attribute ...
0
votes
1
answer
231
views
How to change slug before use in friendly_id gem?
I am trying to convert slugs to normal characters before using it in Friendly ID, but it does not work:
class CompanyJob < ApplicationRecord
extend FriendlyId
def self.convert_slug(title)
...
0
votes
1
answer
71
views
Rails not differentiating between two resources nested in the same namespaces
I have two types of products that are nested under the same categories. The routes I have setup are
resources :categories, path: '/', only: [:show] do
resources :subcategories, path: '/', only: [:...
0
votes
1
answer
66
views
How to use named routes when using FriendlyId at the root path in Rails
I have a basic Page model in Rails that I'm using with FriendlyId to allow admins to create pages like "/about" or "/contact".
I have the following in my routes file (config/routes....
0
votes
1
answer
103
views
undefined method `slug_limit=' for friendly_id
When I set the slug_limit on friendly_id as per the documentation in the initializer, I see the following error:
Failure/Error: extend FriendlyId
NoMethodError:
undefined method `slug_limit=' for #&...
1
vote
1
answer
138
views
Add @ to friendly_id slug Ruby on Rails
I am having a problem adding the @ symbol to slug in my Rails application.
Here is the code from the user model:
validates_format_of :username, with: /^[a-zA-Z0-9_.](?!\w*__\w*)\w+$/, multiline: true
...
1
vote
1
answer
187
views
How to add id to Friendly_id slug?
I'm interested in generating slug with both title and id. Otherwise, I would get errors like post collection route overriding single post route.
class Post > ApplicationRecord
extend FriendlyId
...
1
vote
1
answer
277
views
Prevent IDs with Record.friendly.find param
I'm using FriendlyId and Rails.
I would like to support finding by the slug:
https://example.com/restaurants/plaza-diner
But NOT support finding by its ID:
https://example.com/restaurants/23
I'm using ...
1
vote
0
answers
52
views
Getting rails tests to reflect actual behaviour with FriendlyID
The following class has only one mandatory relation and one validation
class Shop < ApplicationRecord
extend FriendlyId
friendly_id :name, use: :slugged
validates :name, presence: true, ...
0
votes
1
answer
369
views
Friendly_id not working version 5.3 rails 6
I've been working on an app and I installed friendly_id version 5.3 and everything was working.
However, recently working on the app I've found friendly_id not working at all on anything it's been ...
0
votes
1
answer
55
views
How to differentiate between :ids in routes/URL that belong to different models using FriendlyID?
I'm wondering how to generate a url that includes friendly ids for two different models. For example, if you have a post titled 'Rails Tutorial' and belonging to a particular User named 'Michael', and ...
0
votes
0
answers
102
views
Can not transliterate strings with CP850 encoding
For my Blog App I use FriendlyId to generate slugs.
In irb post creation process following message appears:
ArgumentError (Can not transliterate strings with CP850 encoding)
I found out that the ...
0
votes
1
answer
450
views
Rails friendly_id removing non ascii characters for url generation
I want to auto generate the slug based on the title and author of the book, which can be in any language. Using friendly_id with rails, and when there are non-ascii characters, it just removes them. I ...
1
vote
0
answers
40
views
FriendlyID with overridable tree-path slugs
I'm currently using Ancestry to manage a model structured as a tree, though the exact implementation of the tree doesn't really matter.
Given a model with the following properties:
class Item < ...
2
votes
1
answer
160
views
friendly_id gem, smaller hash?
Given that my slug candidate is my title, and it is already used, the slug will return something like: my-title-49c9938b-ece5-4175-a4a4-0bb2b0f26a27
Is it possible to have friendly_id return a ...
2
votes
1
answer
4k
views
Associate USB Video Capture Device Friendly Name with OpenCV Port Number in Python
I want to get the Friendly Names and USB port numbers for external USB video capture devices using Python on a Windows platform. I’m using OpenCV to capture video from a USB capture device. OpenCV ...
0
votes
0
answers
145
views
How to use friendly_id to find product?
I installed friendly_id according to the instructions. And use it for products.
For show i use:
@product = Product.friendly.find(params[:id])
And it works.
But I have a couple of question, on its ...
-1
votes
2
answers
486
views
(Friendly_id) How to use slug instead of id in nested routes?
I have two models - Team and Campaign.
Team has_many :campaigns & Campaign belongs_to :team
Using friend_id gem, I have my team routes working as expected i.e https://localhost/t/myteam
However,...
2
votes
1
answer
370
views
Avoid RecordNotFound exception with friendly_id gem
Is there a way to have friendly.find simply return nil when the slug isn't available in any record, rather than raise the ActiveRecord::RecordNotFound exception?
0
votes
2
answers
80
views
Exclude using friendly_id?
I want to run a controller query and exclude the current (self) record. I can use this:
Model.where.not(slug: params[:id])
That works fine until you manage to pass the record id.
Is there a ...
0
votes
1
answer
73
views
Trying to add :id to the end of paramter in Rails app
I'm trying to modify my url parameter in my app. I'm currently using friendly_id to make the url include the title instead of the id. However I'd like to add the id after the title in the url if ...
1
vote
0
answers
399
views
Friendly ID not working as expected for models Show. Any ways around this?
Issue: I have installed the friendly_id gem, it is working how it supposed to for my Users table, but for my Listings model, the friendly URL to use a :name instead of :id isn't working.
Here's my ...
1
vote
2
answers
257
views
Rails: Using friendly_id/slug with column from associated model
I've got Contact model which I want to be slugged (friendly_id gem). By using the user_name column from User model which Contact model belongs to.
class Contact < ApplicationRecord
belongs_to :...
0
votes
1
answer
234
views
How to set Rails polymorphic model with friendly_id and history
I have a Company and Seo Model (in link below Seo called PublicSlug) with polymophic association and concern similiar to answer
Match multiple models in single Rails route with friendly_id
to build ...
0
votes
1
answer
349
views
Friendly_id preventing edit/new pages due to before_action :find_post
I am using the friendly_id gem to handle URL Slugs and when applying a fix to avoid 404's when the slug changes from the documentation, my code doesn't work properly.
The problem is that it simply ...
1
vote
1
answer
378
views
undefined method `friendly' getting error from controller
I have work on project with ruby on rails and i want to use friendly_id gem. When I install friendly_id gem in my project then add following code according to instructions.
controller:
def show
@...
1
vote
2
answers
778
views
Rails: Friendly_id gem friendly url not working for 1 model, but working for other(s)?
Issue: I have installed the friendly_id gem, it is working how it supposed to for my Users table, but for my Listings model, the friendly URL to use a :name instead of :id isn't working.
Here's my ...
0
votes
1
answer
141
views
How to fix FriendlyID duplicate content for :id and :slug
FriendlyID is consistently showing duplicate content for both /slug and /1. In other words, the correct page is loading for the friendly slug (/new-york), but it's loading the same content for the old,...
0
votes
2
answers
64
views
Undefined 'id' when i use Friendly_id gem
I'm using the friendly_id gem for modifying my urls.
But i have a problem with my likes system.
For the use of friendly_id i change my controller:
@software = Software.find(params[:id])
to
@...
1
vote
1
answer
135
views
How to raise an error on duplicate column slug in FriendlyId?
I use friendly_id gem and if my slug column have duplicate value, gem updates it by adding a unique key. I want raise error already been taken. How can i do this?
0
votes
1
answer
57
views
RoR Simple Friendly Slugs
I'm currently using Friendly_ID to create friendly slugs of the form "/post/friendly-name".
e.g., routes.rb reads:
get '/posts/:id', to: 'posts#show'
HOWEVER, I don't want the "/post" element: the ...
0
votes
0
answers
31
views
Friendly_ID stops working at times, server restart necessary
I'm running a Rails 5.0.6 app with Friendly ID 5.2.4 and everything works fine except that after some time (sometimes a few hours, sometimes a few days) the friendly ids are not working anymore (...
0
votes
1
answer
91
views
subcategories and categories rails friendly_id
Cant seem to get friendly_id to work with with my categories and subcategories. I am using the friendly_id gem as well.
Here is my categories controller
class CategoriesController < ...
1
vote
3
answers
2k
views
Rails 5: Can't find record with friendly id
I just add friendly_id to my application and everything works smooth except one line of code gives me an error.
I get the following error when I try to order a wine from my favorites view.
can't ...
0
votes
1
answer
594
views
Rails 5: FriendlyId TypeError (wrong argument type Symbol (expected Module:))
I am trying to add friendlyid to my application, after I've setup everything I get the following error:
TypeError wrong argument type Symbol expected Module
I inserted extend :FriendlyId and ...
-1
votes
1
answer
1k
views
ActiveRecord::RecordNotFound (Couldn't find Employer without an ID) while using form Rails 5
I checked various solutions that are available, but none seem to address the issue that I am having with my project. I am trying to allow the user to create reviews through the EmployerReview model ...
1
vote
2
answers
1k
views
Prepending a UUID to route to ensure uniqueness of slug
I'm using the friendly_id to add custom slugs to my models and their corresponding urls. Currently I have a setup where a Post belongs to a Board. There will undoubtedly be cases where a post will ...
0
votes
1
answer
134
views
Rails validate uniqueness for the ASCII approximation
I hope the title is not too unclear.
I am making arails app and I have a question about rails validation. Consider this code in the User,rb model file:
validates :name,
presence: true,
...
0
votes
0
answers
50
views
Friendly_id slug_history is updating with wrong slug
When I create a new Invoice in my Rails program friendly_id is updating the history with the new slug. What do I need to do to fix this issue.
Currently I have no idea how to fix this in my program. ...
0
votes
0
answers
126
views
Rails - Multiple Models with root sluggable routes
I'm looking for advice to find the ideal solution that fits within Rails' best practises.
My app has 5 models:
Category
Place
Division
Subdivision
Item (polymorphic)
A Place belongs to a Category. ...
3
votes
3
answers
2k
views
Breadcrumbs list in ActiveAdmin shows wrong name when using friendly_id
I have a model named Company that has code. The column is used for friendly_id.
class Company < ActiveRecord::Base
extend FriendlyId
friendly_id :code, use: :slugged
end
ActiveAdmin doesn't ...
0
votes
1
answer
283
views
How to find_by_id when using friendly_id (for polymorphic relations)
How do I allow find_by_id to work so my comments will work with my posts that have slugs via friendly_id? Is there an alternative approach to doing this?
I have installed a Ruby gem called ...