Is there something wrong with running multiple threads?
When I load the page using action1, it works.
HomeController
def action1
threads = []
threads << Thread.new {@lub = client.tag_recent_media('tag1')}
Thread.new{@tags = client.tag_recent_media('encorebeach')}
Thread.new{@location = client.location_recent_media('16565')}
threads.each(&:join)
end
Home View
<% (@lub+@tags+@location).each do |media| %>
<%= media %>
<% end %>
Here's another controller with a different view
AnotherController
def action1
threads2 = []
threads2 << Thread.new {@lub2 = client.tag_recent_media('tag1')}
Thread.new{@tags2 = client.tag_recent_media('encorebeach')}
Thread.new{@location2 = client.location_recent_media('16565')}
threads2.each(&:join)
end
Another View
<% (@lub2+@tags2+@location2).each do |media| %>
<%= media %>
<% end %>
For the second output I get an error
undefined method `+' for nil:NilClass
I think it is something wrong with the threads. Can someone assist me as to why this is happening? Is it because I already executed a thread in the home page, and then when I want to go to another page, it runs a thread again and it won't work?
Thanks!