我想将推文保存到数据库中,但它不起作用!我正在使用推特宝石。
我的控制器:
class TweetsController < ApplicationController
def save_tweets_into_database
@tweets = Twitter.search("#em2012" "#Italy" "#Spain", :lang => "en", :rpp => 25).results
@tweets.each do |tweet|
@tweet = tweet
@tweet.create
end
end
end
我的模特
require "rubygems"
require "twitter"
class Tweet < ActiveRecord::Base
end
我的观点
<% @title = "liste" %>
<h2>Liste der Tweets über das EM-Finale</h2>
<ul>
<% @tweets.each do |tweet| %>
<li><%= tweet %></li>
<% end %>
</ul>
我的路线
Em2012tweet::Application.routes.draw do
match '/save_tweets', to: 'tweets#save_tweets_into_database'
end
显示此错误:
Twitter::Status:0x007fac9c80a160 的未定义方法“创建”
Rails.root:/Users/xyz/Desktop/Workspace/em2012tweet
app/controllers/tweets_controller.rb:7:in `block in save_tweets_into_database'
app/controllers/tweets_controller.rb:5:in `each'
app/controllers/tweets_controller.rb:5:in `save_tweets_into_database'