whereクエリを使用して新しい配列を定義しようとしていますが、一方向でしか機能しません。
ここにあります:
<%
@children = Array.new
Topic.where(breadcrumb_id: @topic.id).each do |y|
@children.push(y.name)
end
return @children
%>
Returns the array ["Performance Arts", "Visual Arts", "Physical Arts", "Music", "Culinary Arts"] (All topics)
しかし、私はただやりたいです
@children = Topic.where(breadcrumb_id: @topic.id)
return @children.each.name
Returns "undefined method `name' for #<Enumerator:0x007fe92205a1f0>"
何らかの理由で.eachは正しく応答しません...最初の例の最初のwhere呼び出しで機能しますが。違いは何ですか?
配列から直接名前を取得できるようにする方法はありますか?