Skip to content

Instantly share code, notes, and snippets.

@mariozig
Created April 18, 2010 08:06
Show Gist options
  • Save mariozig/370098 to your computer and use it in GitHub Desktop.
Save mariozig/370098 to your computer and use it in GitHub Desktop.
## Issue:
NameError in Admin/tweetsController#index
undefined local variable or method `tweets' for #<Class:0x7fcbe98f68f0>
Rails.root: /home/rails/
Application Trace | Framework Trace | Full Trace
app/models/tweet.rb:23:in `add_tweets'
app/models/tweet.rb:15:in `update_twitter_account'
app/models/tweet.rb:9:in `update_tweets'
app/models/tweet.rb:8:in `each'
app/models/tweet.rb:8:in `update_tweets'
app/controllers/admin/tweets_controller.rb:6:in `index'
## Model
class Tweet < ActiveRecord::Base
# Relationships
belongs_to :user
def self.update_tweets
users = User.all
users.each do |user|
update_twitter_account(user)
end
end
def self.update_twitter_account(user)
tweets = Twitter::Search.new.from(user.twitter_account)
add_tweets(tweets, user.id)
end
#-------------------
private
def self.add_tweets(entries, user_id)
tweets.each do |tweet|
unless exists? :guid => entry.id
create!(
:guid => tweet.id,
:profile_image_url => tweet.profile_image_url,
:from_user => tweet.from_user,
:to_user => tweet.to_user,
:the_tweet => tweet.the_tweet,
:user_id => user_id
)
end
end
end
end
## Controller
def index
if (params[:update_tweets])
Tweet.update_tweets
end
@tweets = Tweet.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @tweets }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment