I have a fairly generic question about how to create a shortlist in rails.
What I currently have is a user and job model where users can register and create/edit jobs etc. What I would like to do is enable users to add jobs they are interested in to a “shortlist” so that they can easily come back to them – I would then want to add these shortlisted jobs to my user dashboard.
I was wondering what would be the best way to implement a setup like this? Would it be best to create a seperate controller for shortlists and make this a nested resource of users and then link my jobs table with my shortlist table in my database?
Would be great to get some ideas from anyone who has implemented anything like this before?
Thanks! 🙂
If I’m understanding correctly, it sounds like you want a
has_and_belongs_to_manyrelationship here as far as the modeling goes –User:
Job:
As far as the controller setup, I would put the job CRUD into a
JobsController, that isn’t namespaced, and add the needed actions for manipulating a particular user’s shortlist into theUsersController.The one assumption I’m making is that me, as a user in your app, can add a job that you created to my shortlist. If this is the case, I would set it up how I just described.