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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:46:34+00:00 2026-06-19T03:46:34+00:00

my code in index.html.erb file is posted below. When I tested in a regular

  • 0

my code in index.html.erb file is posted below. When I tested in a regular ruby file, I did not see any quotes/brackets in output. However, when I use same code in erb file I see quotes and square brackets displayed around each value when viewed in browser. Is there any way to get around this?

---
title: Coast Guard Quiz
---

<%

seaman_recruit = {

    img: "<img src = 'images/USCG_SR.png'>",
    name: "Seaman Recruit",
    en_class: "Seaman",
    abbr: "SR",
}

seaman_apprentice = {
    img: "<img src = 'images/USCG_SA.png'>",
    name: "Seaman Apprentice",
    en_class: "Seaman",
    abbr: "SA",
}

seaman = {
    img:  "<img src = 'images/USCG_SM.png'>",
    name: "Seaman",
    en_class: "Seaman",
    abbr: "SN",
}

ranks = [seaman_recruit, seaman_apprentice, seaman]

ranks.shuffle!

current_rank = ranks.shuffle!.first

%>

<p><%= current_rank.values_at(:img) %></p>
<p class="bld"><%= current_rank.values_at(:name) %></p>
<p><%= current_rank.values_at(:en_class) %></p>
<p><%= current_rank.values_at(:abbr) %></p>
<p><%= current_rank.values_at(:title) %></p>
<p><%= current_rank.values_at(:paygrade) %></p>

For example, I see this:

[“(actual image)”]

[“Seaman”]

[“Seaman”]

[“SN”]

[“Seaman (last name)”]

[“E3”]

And I want to see this:

(actual image)

Seaman

Seaman

SN

Seaman (last name)

E3

  • 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-19T03:46:35+00:00Added an answer on June 19, 2026 at 3:46 am

    .values_at always returns an array. It will optionally accept multiple arguments and return the corresponding values from the hash. Since you’re only giving a single argument, you get an array with one member.

    You just want a standard lookup, either using bracket notation (current_rank[:title], etc) or fetch (current_rank.fetch(:title)). Fetch has the added option of defining a default value to prevent errors when the provided key is not present in the hash: current_rank.fetch(:key) { 'default value' }.

    ERB is generally not the appropriate place to define data or behavior. Assuming you’re using standalone erb templates (not backed by Rails or Sinatra), I would suggest a better option would be to define your templates separate from your ruby code, either in individual files or as strings in a standard ruby file. You can take a look at the documentation for some examples.

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

Sidebar

Related Questions

I have this code in my index.html.erb file in my project: <h1>Listing businesses</h1> <table>
My index.html page for my project needs some Ruby code so I need to
I am loading a WebView in an Android application with the below code: mWebView.loadURL(https://wat.harminson.com/html/index.html);
inside index.html.erb there is the following code <video width=320 height=240 controls=controls> <source src=truffle1.mp4/> Your
I have an html.erb file that does not render anything when the following is
in my code for index.html I use jQuery and have a link with id
I have the following code <xsl:result-document href=output1/output3/index.html format=html> <html> <head> <SCRIPT LANGUAGE=JavaScript> function getParams()
The script is in myusername/public_html/item/index.php code to save file: $filename = $_SERVER['DOCUMENT_ROOT'].'/../data/guestbook.txt'; $filehandle =
I'm building a static website in Ruby on Rails and I have an application.html.erb
I have this chunk on jQuery and currently its living in my index.html.erb and

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.