RailsCasts Pro episodes are now free!

Learn more or hide this

Artur's Profile

GitHub User: kentonwebdesign

Site: http://www.kentonwebdesign.com

Comments by Artur

Avatar

How do I do the same for a authorized user, I've got the following in my controller, model, and index;

Controller:
def index
                @bins = Bins.new
                @bins = Bins.all
                @tw = Newtweets.order("tweet_id desc").limit(100)
        end
def pull
     current_user.newtweets.pull_tweets
     return
end
Model:
def self.pull_tweets
          twitter.home_timeline(since_id: maximum(:tweet_id)).each do |tweet|
                  unless exists?(tweet_id: tweet.id)
                          create!(
                                  tweet_id: tweet.id,
                                  followers: tweet.user.followers_count,
                                  retweets: tweet.retweet_count,
                                  time_date: tweet.created_at,
                                  content: tweet.text,
                                  screen_name: tweet.user.screen_name,
                          )
                  end
          end
  end
Index:
<% @tw.each do |t| %>
                <div class="entry">
                    <div class="selection"><%= check_box_tag :label %></div>
                    <div class="stamp unknown"><%= t.time_date %><br /><span class="date"><%= date.day %>/<%= date.mon %>/<%= date.year %></span></div>
                    <div class="tweet">
                            <p><%= t.content %>
                        <br /><span class="username"><a href="https://www.twitter.com/<%= t.screen_name %>" target="_blank">@<%= t.screen_name %></a></span><span class="followers">Followers:<%= t.followers %></span><span class="retweets">Retweets: <%= t.retweets %></span></p>
                    </div>
                </div>
                <hr style="width:93%;height:1px;margin:-5px auto 10px auto;border:none;border-bottom:1px solid #EDEDED;" />
                <% end %>

As you've guessed it, I'm trying to use a refresh button to pull the route /refresh which runs the controller, that runs the model??

Not sure I'm doing this right. However, going in the console with the following command;

ruby
u.newtweets.pull_tweets

I get an error: NameError: uninitialized constant User::Newtweet

Should I be moving the self.pull_tweets stuff into a controller??

Any suggestions, thank you!