2013-08-27 61 views
0

Twitter寶石無法呈現鳴叫中的鏈接。我如何呈現twitter鏈接以查看?例如鏈接@user或連結#tagTwitter寶石無法呈現鳴叫中的鏈接

查看:

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

控制器:

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 

回答

1

相反linkify的,讓漂亮的Twitter主題標籤,並提到嘗試Twitter的文本寶石。

添加到您的Gemfile

gem 'twitter-text' 

然後添加到您的application_helper.rb

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

然後在您的視圖

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