问题
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'
回答1:
As Logan noted above, I needed to restart my server.
来源:https://stackoverflow.com/questions/8529953/uninitialized-constant-using-twitter-ruby-gem