sql - Why do all but the first row in a table show up as '#' when you call .all in rails console? -


I'm learning about models and databases in rail and when I make a table I can call Get a blank array on all the models, but if I make multiple rows and I call all I get an array where only the first row shows the actual value and Remaining # .

The console does not display all the row values, and if it does not, how can I see all the values ​​of rows without calling .find on each line? ?

irb (main): 001: 0> Todo.all

Select Todo Load (0.1ms) "todos". * To "todos" [# & lt; Todo id: 1, todo_item: "Pick milk", created_t: "2014-07-27 15:45:11", updated_t: "2014-07-27 15:45:11" & gt; #, #] < / Code>

irb (main): 001: 0> Todo.Ol. Seconds

Todo Load (0.1m.

  # & lt; Todo id: 2, todo_item: "Pay Internet bill", created_at: " 2014-07-27 15:47:42 ", updated_at:" 2 014-07-27 15:47:42 "& gt;  

I'm pretty sure that this is a feature of the console, which reduces the output, show you the properties of the model without filling out the output space. If you need to see the actual features So try to collect what you want to see for Are:

  TODO.all.collect {| x | X.todo_item}  

or for the whole thing ...

< Pre> TODO.all.collect {| x | X.inspect}

Write a custom to_s method with one content that you want to see and use most In your model ...

  def to_s "TODO: # {id} - # {todo_item}" end  

and use it like this Do:

  TODO.all.collect {| x | X.to_s}  

The result of custom to_s is that it is very debugging tool and Ruby string Also by injection will be used.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

How to access user directory in lazarus? -

java - Gradle dependencies: compile project by relative path -