Rails显示完整数据库而不是仅显示属性 [英] Rails Displaying Full Database Instead of of Attributes Only

查看:78
本文介绍了Rails显示完整数据库而不是仅显示属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎已经在我的Rails应用程序中弄清楚了一点,以确保正在创建游戏和票证,但是当我尝试将它们显示在html.erb文件中时,整个数据库都正在呈现...全部我想显示的是实际的票证属性.这是它的外观以及与之关联的代码.感谢您的帮助.

I seem to have gotten things to a point in my rails app making sure that games and tickets are being created, but when I try and display them in the html.erb file, the whole database is being rendered...all I'm looking to display is the actual tickets attributes. Here is what it looks like and the code associated with it. Any help is appreciated.

代码是:

 <h1> game id is <%= @g.id %> </h1>

 <h2> Ticket values are: </h2>

 <table>
     <%= @g.tickets.each do |tick| %>

     <tr>
         <td><%= tick.id %></td>
         <% if tick.nickname.blank? %>
         <td> Available</td>
         <% else %>
         <td><%= tick.nickname %></td>
         <% end %>
         <td><%= tick.game_id %></td>
     </tr>
     <% end %>
 </table>

我需要删除在票证值下打印出的完整数据库部分,但是似乎不能不删除所有内容而将其删除.感谢您的帮助.

I need to remove the full database portion that is printed out under ticket values, but cant' seem to have it removed without removing everything. Thanks for your help.

门票控制者为:

  class TicketsController < ApplicationController

    def create
      @ticket = Ticket.new
      @ticket.nickname = params["nickname"]
      @ticket.game_id = params["game_id"]
      @ticket.save
    end

  end

游戏控制器为:

 class GamesController < ApplicationController

 def create
    @g = Game.new
    @g.winning_ticket_num = params["winning_ticket_num"]
    @g.value_per_ticket = params["value_per_ticket"]
    @g.save
    10.times do 
      @g.tickets.create
    end
    render 'games/show'
 end 


 def new
 end

 def show 
 end


 end

推荐答案

删除=

<%= @g.tickets.each do |tick| %>

它应该看起来像这样

<% @g.tickets.each do |tick| %>

这篇关于Rails显示完整数据库而不是仅显示属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆