我試圖建立一個搜索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
中,並且不打算更改頁面嗎?
在此先感謝您的幫助!我徹底難倒了。