Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6220371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:56:42+00:00 2026-05-24T07:56:42+00:00

I want when editing a model to perform some validations so I thought that

  • 0

I want when editing a model to perform some validations so I thought that the best way is to use the

before_update

in Rails.

Can someone provide an example of a custom validator using a before_update call?

For example:

I have a class Topic and I want to allow only the creator of the Topic to be able to change the title.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:56:43+00:00Added an answer on May 24, 2026 at 7:56 am
    # Topic.rb
    before_update :your_custom_validation
    
    private
        def your_custom_validation
            # your code
        end
    

    You can do that with any callbacks. That is, specify the filter and pass it a symbol to the name of your method.

    You may also want to consider adding a user authentication gem like devise and only allowing logged in users to do stuff like that, which goes great with a permissions gem called cancan.

    Edit: (Going to put it here too, even though it’s in the comments below)
    I forgot about order of execution. I would still recommend using something like devise and seeing if the right person is logged in (you can authenticate the user in the controller) or using the validate :custom_method callback to fire off with the other validations. If you’re not the author, validations fail, nothing gets saved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to ensure that a user editing a particular model is saved in
I have a partial view that I use for editing and creating my models.
I want to generate some data for editing, filtered by the choice a user
Wondering if there's any jquery library/plugin that can easily perform the following. At main
In my Ruby on Rails application I want to allow the adding/editing of a
I am editing my user model, and I want to place a foreign key
I have a user model. In it, I have set validations that are used
I want to know the name of the specific editing mode in which the
I am editing a vba program and want to code the vba to click
I want to ensure a user isn't editing the same form data in two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.