我正在使用Twitter gem来搜索用户的特定主题标签的推文。现在我想解析输出并在视图中呈现它但不确定如何。我有以下控制器操作:
def profile_hustle
@profile = Profile.find(params[:id])
@profile_tweets = Twitter.search("#hashtag from:#{@profile.twitter}")
end
这给我的输出如下:
[#<Twitter::Status:0x007fbf331aec40 @attrs={"created_at"=>"Wed, 21 Dec 2011 04:18:39 +0000", "from_user"=>"username", "from_user_id"=>userid, "from_user_id_str"=>"userid", "from_user_name"=>"User Name", "geo"=>nil, "id"=>otherid, "id_str"=>"otherid", "iso_language_code"=>"fr", "metadata"=>{"result_type"=>"recent"}, "profile_image_url"=>"http://a3.twimg.com/profile_images/user/Screen_shot_2009-09-23_at_11.39.35_PM_normal.jpg", "profile_image_url_https"=>"https://si0.twimg.com/profile_images/user/Screen_shot_2009-09-23_at_11.39.35_PM_normal.jpg", "source"=>"<a href="http://twitter.com/">web</a>", "text"=>"Test 2 #hashtag", "to_user"=>nil, "to_user_id"=>nil, "to_user_id_str"=>nil, "to_user_name"=>nil}>, #<Twitter::Status:0x007fbf331aebf0 @attrs={"created_at"=>"Wed, 21 Dec 2011 04:12:27 +0000", "from_user"=>"username", "from_user_id"=>userid, "from_user_id_str"=>"userid", "from_user_name"=>"User Name", "geo"=>nil, "id"=>149341436104544258, "id_str"=>"149341436104544258", "iso_language_code"=>"fr", "metadata"=>{"result_type"=>"recent"}, "profile_image_url"=>"http://a3.twimg.com/profile_images/user/Screen_shot_2009-09-23_at_11.39.35_PM_normal.jpg", "profile_image_url_https"=>"https://si0.twimg.com/profile_images/user/Screen_shot_2009-09-23_at_11.39.35_PM_normal.jpg", "source"=>"<a href="http://twitter.com/">web</a>", "text"=>"Test #hashtag", "to_user"=>nil, "to_user_id"=>nil, "to_user_id_str"=>nil, "to_user_name"=>nil}>]
我想在视图中渲染它以显示文字,如果可能的话&lt;%= link_to%&gt;每条推文的用户Twitter个人资料。我用xml到javascript做了这个,但我遇到了麻烦。
答案 0 :(得分:0)
<% @profile_tweets.each do |tweet| %>
<%= link_to tweet.text, "http://twitter.com/#{tweet.from_user}" %>
<% end %>