ruby-on-rails - 输出到终端而不是 html 文档

标签 ruby-on-rails ruby linux

好的,所以我昨天刚学了 ruby​​。我制作的应用程序跟踪推文并将它们存储在数组中,应该输出到网页,但我不知道正确的语法

输出只是在终端中运行。 html

<h1>Posts#index</h1>
<p>Find me in app/views/posts/index.html.erb</p>
<%= @a %>

ruby

class PostsController < ApplicationController
  TWITTER_COMSUMER_KEY = ""
  TWITTER_CONSUMER_SECRET = ""
  TWITTER_OATH_TOKEN = ""
  TWITTER_OATH_TOKEN_SECRET = ""
  def index
    @a = Array.new(500)

    TweetStream.configure do |config|
       config.consumer_key = TWITTER_COMSUMER_KEY
       config.consumer_secret = TWITTER_CONSUMER_SECRET
       config.oauth_token = TWITTER_OATH_TOKEN
       config.oauth_token_secret = TWITTER_OATH_TOKEN_SECRET
     end
     i = 0
     TweetStream.track('weed') do |status|

     temp = status.text

     if(temp.include? "http")
          a[i] = status.text
          puts "#{status.text}"
          i = i+1
          end
       end
    end
end

最佳答案

有很多我会做不同的事情,但使用您的代码:

更改 a[i]在你看来@a[i] ...

你可以这样做:

<% @a.each do |tweet| %>
  <div class="tweet">
    <%= tweet %>
  </div>
<% end %>

并设置 <div> 的样式适本地。或者使用 <ul><li>如果它更适合您。

关于ruby-on-rails - 输出到终端而不是 html 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15319940/

相关文章:

ruby-on-rails - 没有得到 :id of element using AutoComplete jquery

ruby-on-rails - 在 Rails 中,如何在用户注册时导入用户的 Facebook 联系人?

ruby-on-rails - railstutorial.org 中的 SessionsHelper : Should helpers be general-purpose modules for code not needed in views?

ruby-on-rails - 包括 do ..... end (参数数量错误)错误

ruby-on-rails - 如何使用地理编码 gem 获取时区?

ruby-on-rails - Paperclip & RMagick - PDF 的 3 页缩略图和重命名

c++ - 如何将 OpenSSL 从 32 位配置为 64 位?

ruby-on-rails - ruby on rails 在特定列名后添加一列

python - 如何从搜索中排除可能正在使用或被复制到 python 中的文件?

linux - 多个 crontab 作业,但其中只有一个不应发送电子邮件