我正在按照 Michael Hartl 教程创建一个基本的 twitter 类型应用程序,我正在尝试弄清楚如何让我的帖子出现在关注者的墙上,而不是总是发布到我自己的帖子上。在浏览了我的代码和其他各种答案之后,我相信错误在于我在 HTML 中设置的表单标签......是否有一些非常明显的错误?或者关于您知道的主题的有用教程?
<div class="user-post">
<%= form_for(@micropost) do |f| %>
<div>
<%= f.text_area :content, placeholder: "Compose new micropost...", class: 'create-post-input' %>
<div>
<%= f.submit "Post", class: 'post-button-light' %>
</div>
</div>
<% end %>
<div>
<div class= "scrollBox" >
<% if @user.microposts.any? %>
<% @microposts.each do |micropost| %>
<li>
<%= micropost.content %>
<% if current_user?(micropost.user) %>
<%= link_to "delete", micropost, method: :delete %>
<%end %>
</li>
<% end %>
<%end%>
</div>
</div>
控制器:
def show
@micropost = current_user.microposts.build if signed_in?
@feed_items = current_user.feed.paginate(page: params[:page])
@user = User.find(params[:id])
@microposts = @user.microposts.paginate(page: params[:page])
end
def following
@title = "Following"
@user = User.find(params[:id])
@users = @user.followed_users.paginate(page: params[:page])
render 'show_follow'
end
def followers
@title = "Followers"
@user = User.find(params[:id])
@users = @user.followers.paginate(page: params[:page])
render 'show_follow'
end
微柱控制器:
def create
@micropost = current_user.microposts.build(micropost_params)
if @micropost.save
redirect_to current_user
else
redirect_to current_user
end
end
def destroy
@micropost.destroy
redirect_to current_user
end
private
def micropost_params
params.require(:micropost).permit(:content)
end
def correct_user
@micropost = current_user.microposts.find_by(id: params[:id])
redirect_to root_url if @micropost.nil?
end