0

resource_helper.rb

 def show_checkbox resources
    resources.each do |resource|
      resource.name 
    end.join(' ').html_safe
  end

view

<%= show_checkbox resource %>

This code will output # ,I am sure the value inside is correct. But not sure why it output #

1
  • there is not enough information here for us to really help you. can you show us the content of resource? More context maybe? Commented Dec 12, 2016 at 8:42

1 Answer 1

2

You want to use resources.map, not resources.each.

each will return the value you're iterating over, not the content of the block - giving you something like #<Resource:34531231>. The rest is interpreted as a HTML tag, leaving you with just the # showing.

map will return the value of the block, turning an array of Resource objects into an array of string names, as you want.

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.