I'm trying to write a small feature in a Rails app that uses the random-word gem to generate a random noun, then pluralize it. I've been able to get it working the first time I visit the page in development, but I want the script to run again on each page load. Right now, subsequent page loads (until I bounce the server) give me FiberError in WelcomeController#randomwords
, fiber called across threads
. I attempted to solve this myself, but I'm pretty new to programming and don't really understand how Fibers work. I tried using Queue, but couldn't figure out how to get it to work, again because I don't totally understand the class. How would I go about solving this specific problem?
Source: welcome_helper.rb
def random
noun = RandomWord.nouns.next.split('_').sample.pluralize
if noun.include? "_"
noun = noun.split("_").join.pluralize
else
noun.pluralize!
end
return noun
end