Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amend Sluggable module #974

Closed
ferblape opened this issue Sep 27, 2017 · 4 comments · Fixed by #1978
Closed

Amend Sluggable module #974

ferblape opened this issue Sep 27, 2017 · 4 comments · Fixed by #1978

Comments

@ferblape
Copy link
Member

ferblape commented Sep 27, 2017

Sluggable module works fine, but it can be improved a bit:

  1. The callback that sets the slug should be before_validation. This way, it will work not only after creating but after updating

  2. The module should include two validations:

  • validate the presence of the slug
  • validate the uniqueness of the slug in the scope of the site
@amiedes
Copy link
Contributor

amiedes commented Sep 27, 2017

I have a concern about this concern :trollface:.

If I remember right, the reason why I used before_create was because the slug shouldn't be null (there is a DB constraint for this). This way, when a user doesn't specify a slug in the interface, it gets auto-assigned when the record is created for the first time.

So, a before_validation is not strictly needed, but adding it won't change the current behavior.

@ferblape
Copy link
Member Author

After discussing with @amiedes I have updated the issue.

@apradillap
Copy link
Contributor

Keep in mind when we do the issue that as it has an after_create, in the case, objects like PersonPost the method attributes_for_slug

    def attributes_for_slug
      [created_at. strftime ("%F"), title]
    end

It has an attribute that we haven't in the before_validation and we will have to omit the creation_at for the slug no? cc @ferblape

@ferblape
Copy link
Member Author

Good point, let's us Time.now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants