Bookmarking in Rails 5

Zach Cusimano
loriscode
Published in
2 min readMar 1, 2017

Adding bookmarking or RSVP like functionality into your app.

First you’ll want to create a join table where your location or events users can live. In this example I’m allowing users to bookmark campsites for future use, I called this table “CampsitesUser”.

Project ERD

When creating the model add your user and location’s foreign keys to the new table’s schema.

user_id and campsite_id foreign keys

Next setup your models to configure the correct relationship with the newly created table. In this example “CampsitesUser” belongs_to :user and belongs_to :campsite.

campsite, user and campsite_user models

Setup your CampsiteUser controller method. Within the method identify the current event or location, grab the current user and then shovel that user into the newly created CampsiteUser table.

CampsiteUser method in the Controller

Next setup your views. I allowed users to bookmark a campsite on the campsite#show page. After they press the button it will change status from “Bookmark!” to “Woo”. The saved campsite will then appear on the user#show page.

campsite#show & user#show

Finally view your awesome new feature in your project!!

--

--