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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:02:45+00:00 2026-05-23T07:02:45+00:00

can someone please help in select helper, as I am new to Ruby On

  • 0

can someone please help in select helper, as I am new to Ruby On rails.

I have one json object as follow,

@response = {"status" => "200", "fruit" => [ {
    "id" => 1,
    "name" => "Apple"
  }, {
    "id" => 2,
    "name" => "Mango"
  } ]
}

for which in helper I am returning value “return @response[‘rateCard’]”
Now what I want from this helper to generate such code in view file so it will have selection box like

<select name='fruit'>
<option value="1">apple</option>
<option value="2" selected>mango</option>
</select>

please help

Actually I have one helper “Fruits_helper.rb” which is returning

def selFruit
    @resp = Fruit.getFruit # this will return @response object as mentioned above

    return @resp['fruit']
end

==================================================================================
So in my fruit.html.erb file I am having small piece of code as follows

<%= form_for(:AdminLogin) do |f| %>
<div>

<%= select_tag "fruit", options_for_select(selFruit.each{|fruit,key| [fruit[key]=>'name',fruit[key]=>'id']}) %>

<div>
<% end %>

============================================================================
the above code gives me o/p as

<select name="fruit" id="fruit">
<option value="id1nameApple">id1nameApple</option>
<option value="id2nameMango">id2nameMango</option>
</select>

where I want result as apple

  • 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-23T07:02:46+00:00Added an answer on May 23, 2026 at 7:02 am

    My Problem has been solved just by following code, hope it will help other RoR freshers too

    <%= select_tag "fruit", options_for_select(selFruit.map{|fruit,key| [fruit['name'], fruit['id']]}) %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please help me tune this SQL query? SELECT a.BuildingID, a.ApplicantID, a.ACH, a.Address,
Can someone please help to convert this to linq? SELECT x.contentobjectid, Min(x.city) as city,
Can someone please help convert the following into LINQ To SQL query? select *
Can someone please help me out with printing the contents of an IFrame via
Can someone please point me to the easiest way to have a timer in
Can someone please help me out with a query? In Microsoft SQL Server, I
Can someone please help me with how I can add several different queries to
Can someone please help me to figure out how to create domain classes for
I am pretty new to javascript so I hope someone here can help me
Can someone please help me to force my website to redirect to using www.

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.