Permalink
Browse files

save keyword to database

  • Loading branch information...
1 parent ca54d48 commit 7fee75fad0f31e8c9501ad315d81104804e85604 @ludo committed Sep 7, 2011
@@ -7,7 +7,13 @@ def index
def hashtags
@screen_name = params[:screen_name]
+
+
+
@timeline = Twitter.user_timeline(@screen_name)
+
+ save_keyword(true)
+
@hashtags = []
@timeline.each do |tweet|
@@ -17,7 +23,19 @@ def hashtags
end
+
+ private
+
+ def save_keyword(found)
+ @keyword = Keyword.find_or_initialize_by_value(@screen_name)
+ @keyword.found = found
+ @keyword.count += 1
+ @keyword.save
+ end
+
def username_not_found
+
+ save_keyword(false)
logger.error "username does not exist: #{@screen_name}"
redirect_to( { :action => :index }, :alert => "username does not exist: #{@screen_name}")
end
View
@@ -0,0 +1,2 @@
+class Keyword < ActiveRecord::Base
+end
@@ -0,0 +1,9 @@
+class CreateKeywords < ActiveRecord::Migration
+ def change
+ create_table :keywords do |t|
+ t.string :value
+
+ t.timestamps
+ end
+ end
+end
@@ -0,0 +1,5 @@
+class AddCountToKeyword < ActiveRecord::Migration
+ def change
+ add_column :keywords, :count, :integer, :default => 0
+ end
+end
@@ -0,0 +1,5 @@
+class AddFoundToKeyword < ActiveRecord::Migration
+ def change
+ add_column :keywords, :found, :boolean
+ end
+end
View
@@ -10,6 +10,14 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 0) do
+ActiveRecord::Schema.define(:version => 20110907175048) do
+
+ create_table "keywords", :force => true do |t|
+ t.string "value"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.integer "count", :default => 0
+ t.boolean "found"
+ end
end
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe Keyword do
+ pending "add some examples to (or delete) #{__FILE__}"
+end

0 comments on commit 7fee75f

Please sign in to comment.