0

Suppose my array looks like this:

People => [
  {
    ID => /org/div/emp/123,
    Person => Jack,
    Age => 25
  },
  {
    ID => /org/div/emp/124,
    Person => Frank,
    Age => 45
  },
  {
    ID => /org/div/emp/125,
    Person => Molly,
    Age => 30
  }
]

I'm passing this array to my view using the @People variable.

My view is simple right now:

<h1>People</h1>
  <% @People.each do |person| %>
    <%= uri = person[ID].split("/") %>
    <p>
    Person: <%= person[Person] %> <br/>
    Age: <%= person[Age] %> <br/>
    ID: <%= uri[4] %>
    <br/>
    </p>
  <% end %>

The problem is that, due to how views work, whenever I split person[ID] it is displayed as an array:

People

  ["org", "div", "emp", "123"]

  Person: Jack
  Age: 25
  ID: 123

  ["org", "div", "emp", "124"]

  Person: Frank
  Age: 45
  ID: 124

  ["org", "div", "emp", "125"]

  Person: Molly
  Age: 30
  ID: 125

How do I go about getting the ID from the URI without the array being displayed?

1 Answer 1

1

Don't use <%= uri = person[ID].split("/") %> use <%- uri = person[ID].split("/") %> instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.