Code Monkey home page Code Monkey logo

Comments (5)

vfonic avatar vfonic commented on July 26, 2024

I got it to work.

What's not working, and I didn't know that, is that you can't do:

event = Event.new({ title: 'New title' })
event.slug

You'll get something that looks like (potential future) event mongo ID.

I think friendly_id had this working so I assumed this gem works the same way.

I'm not sure there's much to be added regarding this issue to the README. @dblock Should I submit a PR with a sentence mentioning that slug is generated only on save?

Is there any way to customize the db field? I'd like to use slug string field instead of _slugs array.

from mongoid-slug.

dblock avatar dblock commented on July 26, 2024

I am confused by what's going on above. Is the problem just that trying to access the slug on an unsaved model doesn't give you the slug value? That would be worth documenting. I also think that we should be probably raising an exception trying to access the slug on an unsaved model, so maybe open a feature request?

Customizing the db field seems unrelated. I am pretty sure we don't support a custom name, but would like to. Same re: feature request/PR.

from mongoid-slug.

vfonic avatar vfonic commented on July 26, 2024

I'm pretty sure this is the line of code that returns the id of unsaved record: https://github.com/mongoid/mongoid-slug/blob/master/lib/mongoid/slug.rb#L252

I heavily modified the library to store the slug in slug field in the database, so it works for my use-case, but the code changes I made are definitely not PR ready for this gem/repo.

I'll close this issue as it's resolved. Thank you!
I won't be working on adding mentioned features as I'll be using my messy modified version of the gem. It's only a temporary (which never is) solution for a quick project I'm working on.

Thank you!

from mongoid-slug.

dblock avatar dblock commented on July 26, 2024

Thanks @vfonic. Be aware that the library stores an array of slugs, not a single slug and a lot of care went into ensuring many scenarios work.

from mongoid-slug.

vfonic avatar vfonic commented on July 26, 2024

from mongoid-slug.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.