我正在制作推特副本,现在我正在尝试显示其他用户正在关注的用户的所有帖子。我是 ruby 和 rails 的新手,所以我可能会以一种非常奇怪的方式来做这件事。
这些是我拥有的文件:
session#home.html.erb
<h2 class='User_Header'> Home <h2>
<%= link_to "New Post", controller: "posts", action: "new" %>
<%= link_to "Log Out", :controller => "sessions", :action => "logout" %>
<%= show_tweets("following") %>
session_helper
module SessionsHelper
def show_tweets(opt)
if opt == "following"
@sub = Subscription.where("userID = ?", @current_user.id)
@post = Post.where("user_id = ?", @sub.followingID)
render partial: 'shared/follower_tweets'
end
end
def show_tweet(s)
@post = Post.where("user_id = ?", s.id)
render partial: 'shared/tweet'
end
def tweet_username(p)
@username = User.where("id = ?", p.user_id)
Rails.logger.debug @username.inspect
render partial: 'shared/user'
end
end
_follower_tweets.html.erb
<h2>Tweets</h2>
<table>
<tr>
<th>Username</th>
<th>Tweet</th>
</tr>
<% div_for(@post, class: 'post') do %>
<td><%= tweet_username(@post) %></td>
<td><%= @post.content %></td>
<% end %>
</table>
_user.html.erb
<%= @username %>
会话.rb
class Session < ActiveRecord::Base
attr_accessible :content, :user_id, :followingID, :userID
end
错误
app/views/sessions/home.html.erb 其中第 9 行提出:
undefined method `followingID' for #<ActiveRecord::Relation:0x007fd74b66f8a8>