RoR:为什么我的微博不显示? [英] RoR: why aren't my microposts showing up?

查看:38
本文介绍了RoR:为什么我的微博不显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是用户应该显示的显示视图...

编辑(我稍微更新了这篇文章,你可以在 RoR:我怎样才能让我的微博显示出来?)

<div id="购买"><%=render 'shared/micropost_form_purchase' %>

<div id="销售额"><%=render 'shared/micropost_form_sale' %>

</节><div id="采购清单"><ol class="微博"><%= 渲染@purchases 除非@purchases.nil?%></ol>

<div id="销售清单"><ol class="微博"><%= 渲染@sales 除非@sales.nil?%></ol>

所以表格(部分)加载得很好,但是当我发帖时,在任何一个中,采购清单和销售清单都没有出现.我检查了数据库,它们正在与列中的条目一起创建,指示种类(销售或购买)

表格如下:

<%= form_for (@micropost) do |f|%><div class="字段无缩进"><%= f.text_area :content, placeholder: 你还有什么想买的?"%><%= hidden_​​field_tag 'micropost[kind]', "购买" %>

<%= f.submit "Post", class: "btn btn-large btn-primary" %><%结束%>

<%= form_for (@micropost) do |f|%><div class="字段无缩进"><%= f.text_area :content, placeholder: 你还有什么想买的?"%><%= hidden_​​field_tag 'micropost[kind]', "sale" %>

<%= f.submit "Post", class: "btn btn-large btn-primary" %><%结束%>

此外,这里是 users_controller.rb 的显示部分

 def show@user = User.find(params[:id])@micropost=Micropost.new@microposts = @user.microposts.paginate(page: params[:page])结尾

这里是 microposts_controller.rb 的展示部分

def 显示@micropost = Micropost.find(params[:id])@microposts = Micropost.where(:user_id => @user.id)@purchases = @microposts.where(:kind => "purchase")@sales = @microposts.where(:kind => "sale")结尾

谁能帮帮我?我还需要什么吗?嗯

解决方案

首先,为了确保获得想要的结果,您应该在视图中尝试这样的操作

<%= @sales %>

这应该是您想要的结果的散列.然后,如果这看起来不错,你想做这样的事情

<ol class="微博"><% 如果@sales.any?%><% @sales.each 做 |sale|%><li><%=销售额%></li><%结束%><%结束%></ol>

重复购买

Here is the users show view where they are supposed to show up. ..

edit (I have updated this post slightly you can see it at RoR: How can I get my microposts to show up?)

<section>
  <div id= "purchases">
    <%= render 'shared/micropost_form_purchase' %>
  </div>
  <div id="sales">
    <%= render 'shared/micropost_form_sale' %>
  </div>
</section>

<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>

so the forms (partials) are loading fine, but then when I make a post, in either one, neither the purchases list nor the sales list shows up. I checked the database and they are being created along with an entry in the column indicating kind (either sale or purchase)

Here are the forms:

<%= 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 %>

and

<%= 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 %>

also, here is the show part of the users_controller.rb

 def show
    @user = User.find(params[:id])
    @micropost=Micropost.new
    @microposts = @user.microposts.paginate(page: params[:page])
  end

and here is the show part of the microposts_controller.rb

def show

    @micropost = Micropost.find(params[:id])
    @microposts = Micropost.where(:user_id => @user.id)
    @purchases = @microposts.where(:kind => "purchase")
    @sales = @microposts.where(:kind => "sale")

  end

can anyone help me out? anything else i need? hmmm

解决方案

First, just to be sure you are getting the results you want, you should try something like this in your view

<%= @sales %>

This should be a hash of the results you want. Then, if that looks good, you want to do something like this

<div id="sales_list">
  <ol class="microposts">
    <% if @sales.any? %>
      <% @sales.each do |sale| %>
        <li><%= sale %></li>
      <% end %>
    <% end %>
  </ol>
</div>

And repeat for purchases

这篇关于RoR:为什么我的微博不显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆