views:

40

answers:

1

I'm creating a permissions table for People & Books

In the permissions table I have: Permission.ID, user.id, book.id

I want an admin to be able to set permissions for Users<>Books.

When the user selects the permissions and clicks submit, in the Rails controller, should I be submitting to /create or /update?

is there a way I can submit to just one whether it's new or an update, and let Rails know to either Create or Update a record based on if a record exists per a UserID And BookID?

Thanks

A: 

If they're editing an existing record just submit to update. If they are creating a new record and you're making sure there aren't any duplicates, try using find_or_create_by inside your create method.

Jarrod