【发布时间】:2012-06-09 23:39:28
【问题描述】:
我正在尝试构建一个在 Twitter 上搜索图像的应用程序。在我到达那里之前,我需要跳过构建一个将值输入函数的工作搜索字段的令人生畏的障碍。
在由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
两个问题:
执行搜索后,我的搜索查询没有被传递到 GrabTweets 函数中,正如 URL 所证明的那样:
http://localhost:3000/?action=search&class=grabTweets&method=get(搜索查询是单词“bridge”
我的代码有什么问题,搜索查询没有正确执行。
鉴于我希望搜索结果显示在 root_path 中并且不打算更改页面,我应该将控制器中的代码放在 def home 或 def search 中吗?
提前感谢您的帮助!我彻底被难住了。
【问题讨论】:
标签: ruby-on-rails ruby forms search