I’m pretty new to Ruby on Rails, forms lately have been giving me all kinds of trouble so your help and support here would be very valuable.
In my home.html.erb file I have this code:
<%= form_tag({:controller => "pages", :action => "search"}, :method => "get", :class => "grabTweets") do %>
<%= text_field_tag(:tweets)%>
<% end %>
I’m trying to take the value that the user enters into that search field and pass it into a function called grabTweets that contains the following code:
def grabTweets(mySearch)
@tweet = Twitter.search(mySearch + "[pic] "+" instagr.am/i/", :rpp => 2, :result_type => "recent").map do |status|
@tweet = "#{status.text}" #class = string
urls = URI::extract(@tweet, "http") #returns an array of strings
end
end
The my form code in home.html.erb renders correctly but doesn’t communicate with the grabTweets function. As much Googling and tinkering as I do, I can’t seem to figure out the answer. The code in home.html.erb adds this to the end of my localhost URL: /assets?utf8=✓&tweets=google, so the search isn’t being routed correctly.
Thanks in advance!
There are two things: first you need to make sure that your url gets routed to the write controller
ought to do it.
Then in your PagesController’s search action, call
and do something interesting with the results. Obviously if
grabTweetsisn’t an instance method on your controller then you’d need to adjust how you’re calling it.