我试图建立一个搜索Twitter如需查看图像的应用程序。在我到达那里之前,我需要跳过构建一个工作搜索字段的恐吓障碍,该字段将一个值提供给函数。搜索查询没有出现在URL中的简单搜索应用程序
在那种年代由Pages controller
控制我index.html.erb
文件,我有这样的代码:
<%= form_tag root_path ({:controller => "pages", :action => "search", :method => "get", :class => "grabTweets" }) do %>
<%= text_field_tag :tweets, params[:tweets] %>
<% end %>
在我Pages controller
我:
def search
def grabTweets
@tweet = Twitter.search(params[:tweets] + "[pic] "+" path.com/p/", :rpp => 3, :result_type => "recent").map do |status|
@tweet = "#{status.text}" #class = string
@urls = URI::extract(@tweet, "http") #returns an array of strings
end
end
end
两个问题:
我的搜索查询ISN没有被传递到grabTweets函数中,如搜索后执行的URL所证明的那样:
http://localhost:3000/?action=search&class=grabTweets&method=get
(搜索查询是单词“桥”
这有什么错我的代码,搜索查询没有被正确执行。
我的代码在控制器中应该放在def home
或def search
,因为我希望搜索结果显示在root_path
中,并且不打算更改页面吗?
在此先感谢您的帮助!我彻底难倒了。