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 431481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:58:45+00:00 2026-05-12T19:58:45+00:00

Background Currently, I am working on a Rails application. I have different products that

  • 0

Background

Currently, I am working on a Rails application. I have different products that can be processed through different vendors. All vendors require a text file in a particular format in order to process the orders.

I decided to use a Factory class to generate instances of the Formatter classes that will render the order information in the proper format.

In the factory class I was considering using the following code:

class ExportFactory
  def self.exporter_class_for_vendor(vendor_name)
    class_name = "ProductExporter#{vendor_name}".gsub(' ','').camelize
    class_name.constantize
  end
end

Question

Would it be save to use ActiveSupport::CoreExtensions::String::Inflections.constantize on data submitted by a user? Or, should I just hard-code the class names.

Note: In this particular application, the only users that would be able to change the given data would be admin users that have full control throughout the system.

  • 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-12T19:58:45+00:00Added an answer on May 12, 2026 at 7:58 pm

    It should be safe, but it depends on what you are doing with it after.

    If, for example, you are later calling #delete on the class, the input of File would be dangerous.

    My preferred approach is to keep all user accessible classes of this nature in a module, then validate user input against that module’s #constants. This ensures you are opening up just a small sub section of the ruby namespace to the user, and also allows you to create drop downs so users can select the module, rather than just guessing the names.

    Another way of providing this same level of security is to prefix the name of this module full of available classes on the start of the user input.

    module AvailableClasses
      Foo = ::Foo
      Bar = ::Bar
    end
    
    validates_inclusion_of :user_input, :in => AvailableClasses.constants
    
    AvailableClasses.const_get(user_input)
    
    "AvailableClasses::#{user_input}".constantize
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem Background I am currently working on a camel based ETL application that processes
i'm working with a multi-threaded program (using pthreads) that currently create a background thread
I'm currently working with a textbox that has a background. I was wondering if
Good Morning All, I have created a different background and a few other images
I'm currently working my way through the book Teach Yourself Android Application Development in
Background: I'm currently debugging an application written over a custom-built GUI framework in C++.
First a bit of background. I have been working on the MS platform for
Background about myself: I have about 3 years experience working in Java/J2EE. I am
Some background I'm currently working on a mobile site so I keep switching user
I am currently working on an in house GIS app. Background images are loaded

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.