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

Question re: generating paths/urls when using scoped slug #237

Open
raphaelcm opened this issue Mar 22, 2017 · 5 comments
Open

Question re: generating paths/urls when using scoped slug #237

raphaelcm opened this issue Mar 22, 2017 · 5 comments

Comments

@raphaelcm
Copy link

Apologies for posting a question here, but I searched for a long time and couldn't find the answer.

I'm creating a slug on User that is scoped to Company. Everything works well, except generating paths/urls.

user_achievements_path(@user) generates /users/robert/achievements, but there are multiple roberts who belong to different companies, so the achievement action retrieves the wrong robert when it does a standard lookup of User.find(params[:id]).

Changing @user to @user.id works, but I'd rather not have to do that all over the place. Is there a more elegant solution?

Thank you.

@dblock
Copy link
Collaborator

dblock commented Mar 23, 2017

It sounds like the path is wrong, it should include the company in there, shouldn't it? How is that user_achievements_path generated? AFAIK that's not something that comes from mongoid-slug.

@raphaelcm
Copy link
Author

no, the path is not the issue. These are all working paths - the only change is the addition of mongoid-slug.

@raphaelcm
Copy link
Author

The question is, is there a setting or change we can make to force the url/path generators to use the ID of an object, rather than the slug?

@dblock
Copy link
Collaborator

dblock commented Mar 24, 2017

I honestly don't know, I'll leave this open maybe you can dig this up?

@dblock dblock added the bug? label Mar 24, 2017
@artfuldodger
Copy link
Contributor

Overriding User#to_param to return id will result in the default url generation being fixed. mongoid-slug overrides it to return the slug here: https://github.com/mongoid/mongoid-slug/blob/master/lib/mongoid/slug.rb#L281

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

No branches or pull requests

3 participants