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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:54:27+00:00 2026-06-12T16:54:27+00:00

I have a field (string) in DB that stores a list of values gotten

  • 0

I have a field (string) in DB that stores a list of values gotten from checkbox if they are checked:

Example:

checkbox1 [X] //Value 1
checkbox2 [ ] //Value 2
checkbox3 [X] //Value 3
checkbox4 [X] //Value 4
checkbox5 [ ] //Value 5

It stores in database the string “— -‘1’ -‘3’ -‘4′” (w/o the double quotes) I don’t know why because in my form I have:

<%  SoProfile::LANGUAGES.each do |key, value| %>
  <div class="fluid">
    <%= f.label :languages,class: "checkbox" do %>
      <%= key %> <%= f.check_box :languages, {:multiple => true}, value, nil %>
    <% end %>
  </div>
<% end %>

in the model (I don’t want to use a DB table for this):

LANGUAGES = { Espanol: 1, Ingles: 2, Portugues: 3, Italiano: 4, Mandarin: 5 }

anyways, it stores that string “— -‘1’ -‘3’ -‘4′” for the example above, I want to show a country flag according to the language instead of putting the language name.

I’ve created a helper method for this:

def insert_languages(string)
  string.scan(/\d/).each do |i|
    case i
      when i == "1"
        content_tag(:div,"",class: 'flag flag-co')
      end
  end
end

that is called in my view:

<tr>
  <td>Idiomas <br /> 
    <%= insert_languages(@so_profile.languages) %>                                                                                   
  </td>
</tr>

But the helper method won’t pass from .scan and will print out the hash [“1” “3” “4”] directly, it is, it never reaches the case code, like if there were a return in the string.scan(.. line of code.

How can I prevent rails from returning the hash and instead print the flag?

  • 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-12T16:54:28+00:00Added an answer on June 12, 2026 at 4:54 pm

    Try changing your method to following:

    def insert_languages(string)
      result = ""
      string.scan(/\d/).each do |i|
        case i
          when "1"
            result += content_tag(:div,"",class: 'flag flag-co')
          end
      end
      result
    end
    

    You’re getting hash since ruby returns values from .each block. Ruby returns last value from function implicitly. About your storing method – I suggest you reconsider your storage method. In mongoid, for example, you can use arrays. For active record something like that could solve your problem.

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

Sidebar

Related Questions

I have a DataTable that contains a multi-select choice field (string). Values in the
I have to convert an incoming String field into a BigDecimal field that would
I have async methods that returns an objects public static IEnumerable<Users.User> GetUsers(IEnumerable<string> uids, Field
Suppose I have this annotation @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Name { String value(); }
I have annotated a String field with @NotEmpty tag. When I try to persist
I have a model for assessment criteria which has a :label field containing string
I have an input field whose name is an MD5 string e.g.: <input type=hidden
I have a database with a ValidDate field - it's a string(we made a
I have a nvarchar(50) field in my table. When I save a string with
I Have a object which the following field : boost::unordered_map<std::string, std::shared_ptr<Foo> > m_liste_; I

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.