I have the following code, using the twitter
gem in ruby on rails. It does not return the correct time for tweets created, although I have set my time zone in application.rb
and have also set it here. It returns three hours ahead of the time the actual tweet was created.
<% TwitterFeed.userTweets.each do |tweet| %>
<blockquote>
<%= parsed_tweet tweet %>
<% time_est = tweet.created_at.in_time_zone('Eastern Time (US & Canada)')%>
<br><small><%= (time_est.strftime("%m/%d/%y %I:%M%p %z")) %></small>
</blockquote>
<% end %>
I have the following code in my application_helper.rb
to parse the links from the tweet
object that is returned
module ApplicationHelper
def parsed_tweet tweet
_parsed_tweet = tweet.full_text.dup
tweet.urls.each do |entity|
html_link = link_to(entity.display_url.to_s, entity.expanded_url.to_s, target: '_blank')
_parsed_tweet.sub!(entity.url.to_s, html_link)
end
tweet.media.each do |entity|
html_link = link_to(entity.display_url.to_s, entity.expanded_url.to_s, target: '_blank')
_parsed_tweet.sub!(entity.url.to_s, html_link)
end
_parsed_tweet.html_safe
end
end
I have the following code in my twitter_feed.rb
file where I keep all my functions.
def self.userTweets
client.user_timeline("twitter", count: 5, exclude_replies: true, include_rts: false)
end
I am using version 6.2.0 of the twitter
gem.