gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 11:24:59 25 4
gpt4 key购买 nike

好的,所以我昨天刚学了 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com