(Ruby)获取内部服务器错误消息

时间:2015-02-22 23:21:20

标签: ruby

我一直试图找出我的2个代码发生了什么,但它们并没有连接在一起。

这是我的.rb文件:

require 'sinatra'
require 'twitter'
require 'erb'
include ERB::Util

config = {
    :consumer_key =>  '..' ,
    :consumer_secret => '..' ,
    :access_token => '..' ,
    :access_token_secret => '..'
}

client = Twitter::REST::Client.new(config)

get '/following' do
  buddy = client.friends('skg22')
  @follow = buddy.take(20)
  erb :following
end

以下.elb文件:

<!DOCTYPE html>
<html>
<head>
  <title>Twitter Management Interface</title>
</head>
<body>

<h1>Twitter Management Interface</h1>
<h2>List of Friends</h2>

<% unless @follow.nil? %>
    <table border="1">
      <tr>
        <th>ID</th>
        <th>User</th>
      </tr>

      <% @follow.each do |friend| %>
          <tr>
            <td><%= friend.id %></td>
            <td><%= friend.user.screen_name %></td>
          </tr>
      <% end %>
      </table>

    <% else %>
        <p>No friends.</p>
    <% end %>
</body>
</html>

在过去的几个小时里,我一直在疯狂地试图找出错误是什么,但我所做的每一次修改尝试似乎都没有消除错误信息。

2 个答案:

答案 0 :(得分:0)

如错误消息所示,Twitter::User对象不响应方法user.

尝试在视图中删除此行:

<td><%= friend.user.screen_name %></td>

答案 1 :(得分:0)

.rb文件

require 'sinatra'
require 'twitter'
require 'erb'
include ERB::Util

config = {
    :consumer_key =>  '..' ,
    :consumer_secret => '..' ,
    :access_token => '..' ,
    :access_token_secret => '..'
}

client = Twitter::REST::Client.new(config)

get '/following' do
  buddy = client.friends('skg22')
  @follow = buddy.take(20)
  erb :following
end

.ERB文件

<!DOCTYPE html>
<html>
<head>
  <title>Twitter Management Interface</title>
</head>
<body>

<h1>Twitter Management Interface</h1>
<h2>List of Friends</h2>

<% unless @follow.nil? %>
    <table border="1">
      <tr>
        <th>ID</th>
        <th>User</th>
      </tr>

      <% @follow.each do |friend| %>
          <tr>
            <td><%= friend.id %></td>
            <td><%= friend.screen_name %></td>
          </tr>
      <% end %>
      </table>

    <% else %>
        <p>No friends.</p>
    <% end %>
</body>
</html>