这是用户显示他们应该显示的视图。..
<section>
<div id= "purchases">
<%= render 'shared/micropost_form_purchase' %>
</div>
<div id="sales">
<%= render 'shared/micropost_form_sale' %>
</div>
</section>
<%= @sales %> <%# This is just to see if it outputs anything. It doesn't :( %>
<div id="purchases list">
<ol class="microposts">
<%= render @purchases unless @purchases.nil? %>
</ol>
</div>
<div id="sales list">
<ol class="microposts">
<%= render @sales unless @sales.nil? %>
</ol>
</div>
所以表格(部分)加载得很好,但是当我发帖时,无论是购买清单还是销售清单都没有出现。我检查了数据库,它们正在与列中指示种类(销售或购买)的条目一起创建。
以下是表格:
<%= form_for (@micropost) do |f| %>
<div class="field no-indent">
<%= f.text_area :content, placeholder: "What's something else you want to buy?" %>
<%= hidden_field_tag 'micropost[kind]', "purchase" %>
</div>
<%= f.submit "Post", class: "btn btn-large btn-primary" %>
<% end %>
和
<%= form_for (@micropost) do |f| %>
<div class="field no-indent">
<%= f.text_area :content, placeholder: "What's something else you want to buy?" %>
<%= hidden_field_tag 'micropost[kind]', "sale" %>
</div>
<%= f.submit "Post", class: "btn btn-large btn-primary" %>
<% end %>
另外,这里是 users_controller.rb 的显示部分
def show
@user = User.find(params[:id])
@micropost=Micropost.new
@microposts = @user.microposts.paginate(page: params[:page])
end
这是 microposts_controller.rb 的显示部分
def show
@micropost = Micropost.find(params[:id])
@microposts = Micropost.where(:user_id => @user.id)
@purchases= @microposts.collect{ |m| m if m.kind == "purchase"}.compact
@sales = @microposts.collect{ |m| m if m.kind == "sale"}.compact
end
此外,借助这篇文章 (http://stackoverflow.com/questions/12505845/ruby-error-wrong-number-of-arguments-0-for-1#12505865) 变量@microposts、@purchases 和@sales 都在控制台中正确输出。
谁能帮我吗?
编辑:使用控制台中给出的答案所建议的范围(它正确输出所有内容,但它们仍然没有显示在视图中。这是否意味着我的用户显示页面的语法有问题?
编辑2:
这是视图/microposts/_micropost.html.erb 代码
<li>
<span class="content"><%= micropost.content %></span>
<span class="timestamp">
Posted <%= time_ago_in_words(micropost.created_at) %> ago.
</span>
<% if current_user?(micropost.user) %>
<%= link_to "delete", micropost, method: :delete,
confirm: "You sure?",
title: micropost.content %>
<% end %>
</li>