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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:23:16+00:00 2026-06-03T20:23:16+00:00

I am trying to use a hash to display a form : PREFIX_STR =

  • 0

I am trying to use a hash to display a form :

PREFIX_STR = "Prefix"
FIRST_STR = "First Name"

NEW_USER_HASH = Hash.new
NEW_USER_HASH[ "prefix" ] = { "label" => PREFIX_STR, "type" => "text_field" }
NEW_USER_HASH[ "first" ] = { "label" => FIRST_STR, "type" => "text_field" }

And in the new.html.erb, I have:

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
  <%= devise_error_messages! %>

  <% NEW_USER_HASH.each do |column_name,field_info|  %>
    <div class="field">
      <%= f.label field_info["label"] %>
      <%= f.text_field column_name %>
    </div>
  <% end %>

This works fine, but instead of f.text_field, I want that to be what’s in field_info[“type”]. Nothing I tried worked. Any ideas?

Thanks

  • 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-06-03T20:23:17+00:00Added an answer on June 3, 2026 at 8:23 pm

    You might try f.send(field_into["type"], column_name).

    (Edited to remove “to_sym“, which a commenter tells me is unnecessary (I thought send required symbols.)

    Why this works: some_object.send("hello") is simply another way of writing some_object.hello. In Ruby, invoking a “method” on an object is actually a form of message passing — you’re sending a message to that object, and the object interprets it as a method invocation (or doesn’t — with ruby metaprogramming something that looks like a method call need not be).

    In this case, you have an object f which represents a form_helper object, so when you call f.text_field, you’re sending a message to that object. By using f.send, you do the same thing, except you can generate the content of that message dynamically.

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

Sidebar

Related Questions

I've been trying to use a MD5 hash as a key name on AppEngine,
When trying to use the new hash syntax in Ruby 1.9.2 in a Ruby
I am trying to hash a string then use that hash as the name
I'm getting a Can't use an undefined value as a HASH reference error trying
I'm trying use self-signed certificate (c#): X509Certificate2 cert = new X509Certificate2( Server.MapPath(~/App_Data/myhost.pfx), pass); on
Trying to use this code to connect the AD PrincipalContext context = new PrincipalContext(ContextType.Domain,
I am new to powershell and was trying to use the example script posted
I'm trying to use Hash object like as ActiveRecord Model within FormHelper: <% hash
I'm trying to use CHDB (hash table caching) for PHP (http://pecl.php.net/package/chdb). I end up
I am trying to use Double Hashing to hash a String key into 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.