0

If I am getting parent nodes via and outputting them as a sort of bread crumb list, how do I map both the name of the classification and id to bu8ild a link_to?

<% @parents.map(&:name).each do |parent| %>
    <%= link_to parent, new_sr_path(class_id: parent, sub: :true), class: "form-control" %><svg ...</svg>
<% end %>

@parents = @classification.ancestors.to_a.reverse if params[:class_id].present?

1 Answer 1

1

You should iterate through your objects, instead of the names of your objects (generated by the .map(&:name) call):

<% @parents.each do |parent| %>
  <%= link_to parent.name, new_sr_path(class_id: parent.id, sub: :true), class: "form-control" %>
<% end %>

NOTE Having a real instance give you the ability to call all instance methods defined on that object: parent.name, parent.id, ...

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

1 Comment

I swear I tried that ha. Thanks! That is much easier.

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.