I'm very new to coding and am working on my first rails app. I'm using the Wordnik api to return synonyms of words. So far so good. The code below works, so long as I only use one word.
Code below is in index.html.erb
<%= form_tag "/search", method: "GET" do %>
Start Smithing:
<%= text_field_tag :search_word %>
<%= submit_tag "get those synonyms" %>
Code below is in the Wordnik controller
class WordnikController < ApplicationController
def search
query = params[:search_word]
@words = Wordnik.word.get_related(query, :type => 'synonym').first["words"]
end
end
I'm trying to figure out how to input an entire phrase or sentence in the search and have the API return synonyms for each individual word in the sentence. This would require splitting the symbol and then passing each word individually into
Wordnik.word.get_related(query, :type => 'synonym').first["words"]
Problem is, I have zero idea how to do this. I was trying to do
query = params[:search_word].to_s.split
but that obviously didn't work.
I couldn't find anything in the Symbol documentation and I also found this question here on Stack Overflow.
Anyone have any thoughts that would point me in the right direction?