这是我的show.html.erb文件。
<% provide(:title, @user.name) %>
<div class="row">
<aside class="span4">
<section>
<h1>
<%= gravatar_for @user %>
<%= @user.name %>
</h1>
</section>
<section>
<%= render 'shared/stats' %>
</section>
</aside>
<div class="span8">
<%= render 'follow_form' if signed_in? %>
<% if @user.microposts.any? %>
<h3>Microposts (<%= @user.microposts.count %>)</h3>
<ol class="microposts">
<%= render @microposts %>
</ol>
<%= will_paginate @microposts %>
<% end %>
</div>
</div>
_follow.html.erb部分文件:
<%= form_for(current_user.relationships.build(followed_id: @user.id),
remote: true) do |f| %>
<div><%= f.hidden_field :followed_id %></div>
<%= f.submit "Follow", class: "btn btn-large btn-primary" %>
<% end %>
_unfollow.html.erb部分文件:
<%= form_for(current_user.relationships.find_by_followed_id(@user),
html: { method: :delete },
remote: true) do |f| %>
<%= f.submit "Unfollow", class: "btn btn-large" %>
<% end %>
我的_follow_form.html.erb部分:
<% unless current_user?(@user) %>
<div id="follow_form">
<% if current_user.following?(@user) %>
<%= render 'unfollow' %>
<% else %>
<%= render 'follow' %>
<% end %>
</div>
<% end %>
编辑:我还想说我正在使用Bootstrap。当我检查用户页面时,会出现span4和span8这两个类,但是有一个完整的空白,其中应该是“follow_form”。
编辑:这个问题在几年前就被回答了:)
答案 0 :(得分:0)
我遇到了同样的问题,您可以通过执行以下更改来纠正此问题:
步骤1) 在app / views / users / show.html.erb中 从这里改变代码:
<div class = "span8">
<%= render 'follow_form' if signed_in? %>
<% if @user.microposts.any? %>
到此:
<div class = "span8">
<%= render 'shared/follow_form' if signed_in? %>
<% if @user.microposts.any? %>
第2步) 在部分app / views / shared / _follow_form.html.erb
中更改此代码:
<% unless current_user?(@user) %>
<div id="follow_form">
<%if current_user.following?(@user) %>
<%= render 'unfollow' %>
<% else %>
<%= render 'follow' %>
<% end %>
</div>
<% end %>
到此:
<% unless current_user?(@user) %>
<div id="follow_form">
<%if current_user.following?(@user) %>
<%= render 'shared/unfollow' %>
<% else %>
<%= render 'shared/follow' %>
<% end %>
</div>
<% end %>