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

  • Home
  • SEARCH
  • 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 6858815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:12:23+00:00 2026-05-27T02:12:23+00:00

is there any way how to execute validation directives saved in database ? See,

  • 0

is there any way how to execute validation directives saved in database ?

See, i don’t have staticaly defined attributes by database columns but are defined as row-type.

Examle:

Have groups and attributes. Every group should have different attributes.

Groups: id, name
Attributes: id, name
GroupAttributes: id, group_id, attribute_id, validation(serialize hash as string, same as rails validations)
Articles: id, group_id, attribute_id, value

Form is dynamicaly created based on which group is defined. Group 1 may have different validation for Attribute 1 than Group 1 for same Attribute.

But big problem are validations. I can’t implicit define it in Model. Because i dont know which attributes are want to valide.

I have an idea evaluate string saved in database. But it is critical when there be injected code (which is very unespected).

Do you know any way how to resolve this ?

EDIT:

Principle is: I will write about CMS, it could be more clearer.

CMS have Articles/Posts and Post belongs to Group(Category).

Article should have many Attributes (saved in Attributes db table) like title, content, excerpt, thumbnail image, etc. But these attributes are not fixed in everyone article.

This is because Article belongs to Group. For example: news, posts, properties, reviews, etc.

And there is what i want. When i write some review, it is not neccessary put all fields(attributes) for all groups, only these which are needs.

So my idea is, that is easier to define attributes as “row type” instead “column type”. Any time i’m able to add new, remove old for any Group. There could be tens of attributes (and different) for any group.

After neccessary joins all Models i want to define validation for each one attribute (column “validation” on top) and be used only for these attributes which are associated with group (GroupAttributes).
Give these attribute validations into the Model, like standard Rails “validates”. Without complicated “if” and “unless” conditional statements.

Hope is more detailed than first one.

  • 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-27T02:12:24+00:00Added an answer on May 27, 2026 at 2:12 am

    You can try make custom validator and then loop attributes for group and evaluate their validation parameters on the article. But you will need a proper hash for rails validations.

    GroupAttributes.first.validation => {:presence => true, 
                    :length => {:minimum => 3, :maximum => 254},
                    :uniqueness => true}
    
    #app/models/article.rb
    class Article << ActiveRecord::Base 
      vlidates_with ArticleValidator
    end
    
    #lib/article_validator.rb
    class ArticleValidator << ActiveModel::Validator
      def validate(record)
        record.group.group_attributes.each do |group_attribute|
          record.validates group_attribute.attribute.name, group_attribute.validation
        end
      end
    end
    

    I am not sure if does this works but hope it will be helpfull.

    UPDATE: I was wrong it didn’t work because validates is ActiveModel method not ActiveRecord like I thought. The right answer is you have to add before_validation callback and then setup the right validators.

    class Article << ActiveRecord::Base
    
      before_validation :set_validators
      validates :group_id, :presence => true
    
      privat
    
        def set_validators
          self.group.group_attributes.each do |group_attribute|
            Article.validates group_attribute.attribute.name, group_attribute.validation
          end
        end
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is there any way to execute multiple statements (none of which will have to
Is there any way to execute arbitrary code in Flash, like javascript's eval()? I'd
Is there any way to have something that looks just like a file on
is there any way to execute same code for different events on the page?
Is there any way to execute a scalar-valued function from within a Derived Column
Is there any way to execute same code for different elements on the page?
Is there any way to programmatically execute (start) a SQL Server maintenance plan? We
Possible Duplicate: Java REPL shell Hey, Is there any way to execute Java code
Is there any way to execute Linux commands with c without using execlp() ,
Is there any way to execute a method of a com object inside a

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.