使用 Twitter ruby​​ gem 未初始化的常量 [英] Uninitialized constant using Twitter ruby gem

查看:63
本文介绍了使用 Twitter ruby​​ gem 未初始化的常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Rails 3 应用程序中,我试图显示在我的应用程序中以 @profile.twitter 的形式存储了他们的 twitter 句柄的用户的推文.对于这些用户中的每一个,我想用特定的主题标签搜索他们的推文.我想在我的 ProfilesController 中的一个操作中执行搜索并将推文加载到选项卡式容器中.

我对控制器操作进行了破解,但得到了未初始化的常量 ProfilesController::Twitter.谁能帮忙解释一下为什么?这是我第一次尝试获取这样的数据.下面是我的代码.

profiles_controller.rb:

def profile_tweets@profile = Profile.find(params[:id])@profile.tweets = Twitter.search("#hashtag", "from:#{@profile.twitter}")渲染:json =>@推特结尾

Routes.rb:

resources :profiles 做获取 :profile_about, :on =>:成员获取 :profile_tweets, :on =>:成员结尾

_profile_tweets.html.erb:

<% @tweets.each do |tweet|%><div class="问题"><div class="header"><p class="body"><%= tweet.text %></p>

<%结束%>

profile_tweets.js.erb:

$("#tabs-1").html("<%= escape_javascript(render(:partial => "profile_tweets"))%>");

Gemfile:

gem 'twitter'

解决方案

正如 Logan 上面提到的,我需要重新启动我的服务器.

In my Rails 3 app I am attempting to display the tweets of users who have stored their twitter handle in my app as @profile.twitter. For each of those users I want to search their tweets with a specific hashtag. I'd like to perform the search in an action in my ProfilesController and load the tweets in a tabbed container.

I took a crack at the controller action but am getting uninitialized constant ProfilesController::Twitter. Can anyone help explain why? This is my first crack at fetching data like this. Below is my code.

profiles_controller.rb:

def profile_tweets
  @profile = Profile.find(params[:id])
  @profile.tweets = Twitter.search("#hashtag", "from:#{@profile.twitter}")
  render :json => @tweets
end

Routes.rb:

resources :profiles do
  get :profile_about, :on => :member
  get :profile_tweets, :on => :member
end

_profile_tweets.html.erb:

<% @tweets.each do |tweet| %>
<div class="question">
  <div class="header">
    <p class="body"><%= tweet.text %></p>
  </div>
</div>
<% end %>

profile_tweets.js.erb:

$("#tabs-1").html("<%= escape_javascript(render(:partial => "profile_tweets"))%>");

Gemfile:

gem 'twitter'

解决方案

As Logan noted above, I needed to restart my server.

这篇关于使用 Twitter ruby​​ gem 未初始化的常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆