Comments (6)
No, this isn't possible with FriendlyId right now.
Why you are using FriendlyId on a unique numeric column with no slugs? I think you are probably going to have problems, because your app at some point is not going to know whether you are looking for the record by its id or its friendly_id:
Model.find("100") # is this the friendly_id or the real id? I don't know.
In this case, FriendlyId will look for a record with FriendlyId "100" and if it's not found, it will fail over and look for a record with id 100, which will almost certainly cause problems for your application. If you want to avoid this failover behavior, you would need to use slugs.
from friendly_id.
It's not a numeric value. An order number could be "AW123456" or similar. What I mean to point out is that its generation depends on the ID value.
from friendly_id.
Ah, ok, I misunderstood.
Still, it's not going to be possible with the current FriendlyId. I will likely be changing FriendlyId to generate the slug on before_validate
rather than before_save
, which would solve problems like this. But I probably won't do this for a few more weeks.
If I were you, I would install friendly_id as a plugin or vendored gem for now, and just make a small patch to remove the validations.
from friendly_id.
For now, I've reverted back to the previous version and I'll wait for a resolution. Thanks.
from friendly_id.
It seems this isn't resolved, but the ticket's closed. Have you decided not to change this behavior?
from friendly_id.
In fact, I was not intending to change it. However, I am now working on another feature that would allow models that use slugs to leave the slugs nil. I intend to generalize this functionality to non-slugged models, which would skip the validations when the friendly_id text is nil. This should allow you to do what you are trying to do.
I expect to release this feature later this week.
from friendly_id.
Related Issues (20)
- friendly_id tripping NotNullViolation in Postgres
- `allow_nil: true` on the find method does not work as expected. HOT 7
- normalize_friendly_id not working in a concern HOT 2
- Yard fails to load the gem HOT 5
- Re-enable numeric sequences? HOT 1
- FriendlyId and CanCanCan and redirects
- Generate slug with a `name` and `id` of the record
- :history fails when trying to reuse slugs HOT 1
- Slug regenerated
- Find_by return an nill
- UUID set as slug on failed validations on base column HOT 1
- Error in the doc
- support for Arabic, Persian and other RTL languages
- 5.5.1 release request HOT 3
- Rails 7.1 composite key support
- History does not use parse_friendly_id
- Setting slug_limit in initialiser crashes rspec tests HOT 3
- How can I handle this scoped slug use case without a new option from Friendly ID to disable UUID generation? HOT 2
- Advise users on skipping lazy loaded associations HOT 1
- Collisions when using finder with Rails STI subtypes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from friendly_id.