Note that there are some explanatory texts on larger screens.

plurals
  1. POTwitter Integration using Ruby on Rails
    text
    copied!<p>I have a Ruby on Rails application (Ruby-1.9, Rails-3.2)which integrates with twitter to display the latest tweets containing a particular "keyword" dynamically. But it throws an <strong><em>error</em></strong> as <strong>NameError in TweetsController#create uninitialized constant Twitter::Search</strong> on the browser . I have run the db migrations, restarted the server and tried for various options available on the net. But nothing seems to work. Can anyone help to resolve this error ?</p> <p>The model and controller files are below </p> <p><strong>Tweet.rb (model file)</strong></p> <pre><code>class Tweet &lt; ActiveRecord::Base def self.get_latest_new_year_resolution_tweets(keyword) search = Twitter::Search.new search.containing(keyword).result_type("recent").per_page(100).fetch.each do |tweet_results| twitter_created_at = DateTime.parse(tweet_results.created_at) unless Tweet.exists?(['twitter_created_at = ? AND from_user_id_str = ?', DateTime.parse(tweet_results.created_at), tweet_results.from_user_id_str]) Tweet.create!({ :from_user =&gt; tweet_results.from_user, :from_user_id_str =&gt; tweet_results.from_user_id_str, :profile_image_url =&gt; tweet_results.profile_image_url, :text =&gt; tweet_results.text, :twitter_created_at =&gt; twitter_created_at }) end end end end </code></pre> <p><strong>TweetsController</strong></p> <pre><code>class TweetsController &lt; ApplicationController def index end def create String strText = params[:tweet][:search].to_s Tweet.get_latest_new_year_resolution_tweets(strText) if Tweet.count &gt; 0 Tweet.delete_all end Tweet.get_latest_new_year_resolution_tweets(strText) @tweets = Tweet.order("twitter_created_at desc") render 'index' end end </code></pre> <p><strong>Index.html.erb (The view file)</strong></p> <pre><code>&lt;h1&gt;Twitter connect&lt;/h1&gt; &lt;form action="create" method="post"&gt; &lt;label for="keyword"&gt;Enter Keyword&lt;/label&gt; &lt;input id="keyword" name="tweet[search]" size="30" type="text" /&gt; &lt;input type="submit" value="search" /&gt; &lt;/br&gt; &lt;br&gt; &lt;/form&gt; &lt;/br&gt;&lt;/br&gt; &lt;div id="container"&gt; &lt;% if (@tweets != nil &amp;&amp; @tweets.count&gt;0) then %&gt; &lt;ul&gt; &lt;% @tweets.each do |tweet| %&gt; &lt;li class="&lt;%=cycle('odd', '')%&gt;"&gt; &lt;%= link_to tweet.from_user, "http://twitter.com/#{tweet.from_user}", :class =&gt; "username", :target =&gt; "_blank" %&gt; &lt;div class="tweet_text_area"&gt; &lt;div class="tweet_text"&gt; &lt;%=raw display_content_with_links(tweet.text) %&gt; &lt;/div&gt; &lt;div class="tweet_created_at"&gt; &lt;%= time_ago_in_words tweet.twitter_created_at %&gt; ago &lt;/div&gt; &lt;/div&gt; &lt;/li&gt; &lt;% end %&gt; &lt;/ul&gt; &lt;% end %&gt; &lt;/div&gt; </code></pre> <p>The gemfile is as below</p> <pre><code>source 'http://rubygems.org' gem 'rails', '3.0.3' gem 'sqlite3', '1.3.6',:group =&gt; :development #gem 'ruby-mysql' #gem 'mysql2' group :production do gem 'pg' end gem 'twitter', '4.6.2' </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload