现在,我有以下内容:
<% @headlines.css('a').each do | headline | %>
<%= headline.text %>
<% end %>
<% @top_stories.css('a').each do | top_story | %>
<%= top_story.text %>
<% end %>
(Nokogiri代码)
哪个输出:
"
Heat vs. Bulls, Lakers vs. Clippers on opening night
Free Agent Tracker
Player movement
"
"
"
Heat-Bulls, Lakers-Clippers on opening night
Closer look at sked
Most intriguing
Official release
Suns' Beasley arrested for suspected drugs
"
我想把这两个字符串变成一个ruby散列。类似这样的东西:
{:headlines => ['Kobe ahead of schedule'], etc etc, :top_stories: ['Ex-Lebron pest Stevenson pinning to join Heat', etc etc] }
如何做到这一点?
<%= hash_res %>, <%= headline %> = {}, ''
<% @headlines.css('a').each do | headline | %>
<%= headline %> << <%= headline.text %>
<% end %>
<%= head_res[:headlines] %> = headline
# Do the same thing for the below
<% @top_stories.css('a').each do | top_story | %>
<%= top_story.text %>
<% end %>