I have a Pages table in my DB with a field called position.
How can I increase that value by one before it’s saved?
Even better how can I remove unused positions and give the new record the correct position number?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need a before_save callback:
In your Page model:
You can add any kind of logic to the increase_position method to remove unused positions.