Question

Twitter gem can't render links in tweets. How do I render twitter links to view? for example link to @user or link to #tag

View:

<% @tweet_news.each do |tweet| %>
      <li><em><%= l tweet.created_at %></em>
        <p><%= raw linkify(tweet.text) %></p>            
      <li>
  <% end %>

controller:

def news
account = Settings['twitter'][Locale.get.to_s]

Twitter.configure do |config|
  config.consumer_key = account['consumer_key']
  config.consumer_secret = account['consumer_secret']
  config.oauth_token = account['oauth_token']
  config.oauth_token_secret = account['oauth_token_secret']
end

@twitter_user = account['name']

@tweet_news = Twitter.user_timeline(@twitter_user, {count: 3})

render 'blocks/news', layout: false 
Was it helpful?

Solution

Instead of linkify, to get pretty twitter hashtags and mentions try the twitter-text gem.

Add to your Gemfile

gem 'twitter-text'

Then add to your application_helper.rb

module ApplicationHelper
  include Twitter::Autolink
  # Whatever else you have going on in your helper
end

Then in your view

<% @tweet_news.each do |tweet| %>
  <li><em><%= l tweet.created_at %></em>
    <p><%= auto_link(tweet.text) %></p>            
  <li>
<% end %>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top