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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:45:54+00:00 2026-05-11T20:45:54+00:00

Alright. So I have a table called contacts. In this table I have people

  • 0

Alright. So I have a table called contacts. In this table I have people and there contact information and how their preferred method of contact (Phone, Address, Email, or Fax). I want to be able to have ruby output a list of said people in a manner I could copy paste into a email address bar or such.

<% @contacts.each do |contact| %>
      <%=h contact.contact_name %> < <%=h contact.preferred_method %> >,
<% end %>

This works, but it doesn’t do what I want it to do and I didn’t expect it to. So for a list of people whos preferred choice is email it outputs the list as.

Mike < Email >, Joe < Email >, John < Address >, Sarah < Phone >

instead of

Mike <mike@yahoo.com>, Joe <joe@aol.com>, John <2014 Street>, Sarah <111-111-1111>

It’s calling the preferred_method, but what I actually want it to do is…

<% @contacts.each do |contact| %>
      <%=h contact.contact_name %> < <%=h contact.<%=h contact.preferred_method %> >,
<% end %>

So I would get contact.address or contact.phone depending on their preferred_method. But obviously that doesn’t work. So I thought of trying to assign
<%=h contact.preferred_method %> to a variable.

x = contact.preferred_method

And then have

<% @contacts.each do |contact| %>
      <%=h contact.contact_name %> < <%=h contact.x %> >,
<% end %>

but that doesn’t work either.

Any help would be appreciated.

Mike

  • 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-11T20:45:54+00:00Added an answer on May 11, 2026 at 8:45 pm

    You can use the send method.

    <%=h contact.send(contact.preferred_method.downcase) %>
    

    Invokes the method identified by a symbol or string on the receiving object.

    contact.send(:email) 
    contact.send('address')
    

    Note I set a downcase on the contact.preferred_method because I assume your method name is ’email’ not ‘Email’

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

Sidebar

Related Questions

I have a table called orders this table contains all the information we need.
Alright, here's the deal: I have a nice little 4Gb table called Mails on
Alright so I have a table, in this table are two columns with ID's.
Alright, I have a table of tasks this table has a foreign key which
Alright, let's say I have a table that looks like this: ID | DATE
Alright so I have no idea how to even begin doing this But basically
Alright, so I have this collision detection code, and I'm trying to push the
Alright, I have this program to sparse code in Newick Format, which extracts both
Alright, so I have a table outputting data from a MySQL table in a
Alright, I know questions like this have probably been asked dozens of times, but

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.