# Getting human-readable results

**URL:** <https://www.ruby-forum.com/t/getting-human-readable-results/128683>\
**Category:** Ruby\
**Created:** [February 10, 2008, 12:22pm UTC](https://www.ruby-forum.com/t/getting-human-readable-results/128683 "2008-02-10T12:22:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [February 10, 2008, 12:22pm UTC](https://www.ruby-forum.com/t/getting-human-readable-results/128683/1 "2008-02-10T12:22:59Z")

</div>

How do I get human readable results instead of:

Login: 0123

#Call:0xb714cc94 #Call:0xb714cc58 #Call:0xb714cc30  
Edit | Back

Is there some ruby magic which I can put in the model? I’m hoping that  
the solution isn’t terribly complex. Is there something which I can do  
from the console to figure out what’s going wrong?

thufir@arrakis ~/goodfellow-tool $  
thufir@arrakis ~/goodfellow-tool $  
thufir@arrakis ~/goodfellow-tool $ cat app/models/login.rb  
class Login \< ActiveRecord::Base  
belongs\_to :employee  
has\_many :calls

```
    def report
            reports = []
            calls.each do |call|
                    puts login + "\t" +
                            call.created_at.to_s + "\t"
                            call.comment
            end
    end

```

end  
thufir@arrakis ~/goodfellow-tool $  
thufir@arrakis ~/goodfellow-tool $ cat app/views/logins/show.rhtml  
\<% for column in Login.content\_columns %\>

**\<%= column.human\_name %\>:** \<%=h @login.send(column.name) %\>

\<% end %\>

\<% @login.report.each do |report| %\> \<%= h report %\> \<% end %\>

\<%= link\_to ‘Edit’, :action =\> ‘edit’, :id =\> @login %\> |  
\<%= link\_to ‘Back’, :action =\> ‘list’ %\>  
thufir@arrakis ~/goodfellow-tool $

thanks,

Thufir

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [February 10, 2008, 10:54pm UTC](https://www.ruby-forum.com/t/getting-human-readable-results/128683/2 "2008-02-10T22:54:24Z")

</div>

Thufir wrote:

> Is there some ruby magic which I can put in the model?

Try posting your questions on a forum entitled: C++ or C#.

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [February 11, 2008, 12:40am UTC](https://www.ruby-forum.com/t/getting-human-readable-results/128683/3 "2008-02-11T00:40:08Z")

</div>

On Feb 10, 2:40 pm, Howard R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
[…]

> You’d probably get much better results posting this to the Ruby on Rails  
> mailing list.  
> […]

Parts of this thread are showing up in ruby-talk-google which is a two-  
way portal to the Ruby on Rails mailing list…I think.

Yeh, I must’ve posted to comp.lang.ruby initially, or at least that’s  
where the first reply was. Typically I use gmane. aaarghh.  
Certainly I intended to post to the rails list via gmane, but I guess  
I didn’t.

-Thufir

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [February 10, 2008, 11:40pm UTC](https://www.ruby-forum.com/t/getting-human-readable-results/128683/4 "2008-02-10T23:40:55Z")

</div>

Thufir wrote:

> Is there some ruby magic which I can put in the model? I’m hoping that  
> the solution isn’t terribly complex. Is there something which I can do  
> from the console to figure out what’s going wrong?

You’d probably get much better results posting this to the Ruby on Rails  
mailing list. But in case you aren’t familiar with it .script/console  
may be exactly what you are looking for to try out your models and such  
from a command line, IRB style.

HTH,

Howard

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [February 11, 2008, 1:35am UTC](https://www.ruby-forum.com/t/getting-human-readable-results/128683/5 "2008-02-11T01:35:48Z")

</div>

On Feb 10, 3:39 pm, Thufir [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Feb 10, 2:40 pm, Howard R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
> […]\> You’d probably get much better results posting this to the Ruby on Rails
> 
> > mailing list.
> 
> […]
> 
> Parts of this thread are showing up in ruby-talk-google which is a two-  
> way portal to the Ruby on Rails mailing list…I think.

Woops, I posted to google-talk-ruby (comp.lang.ruby), instead of  
google-talk-rails. Regardless, I got some good pointers 🙂

thanks,

Thufir

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [February 11, 2008, 2:42pm UTC](https://www.ruby-forum.com/t/getting-human-readable-results/128683/6 "2008-02-11T14:42:55Z")

</div>

On 2/10/08, Thufir [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Feb 10, 9:20 am, Phlip [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
> Is there a more ruby-ish or rails way? Somehow, I can’t think that  
> \_why would do it like that, it seems kludgy.
> 
> Let me rephrase the question:
> 
> What’s the optimal technique (idiom?) for getting output from the  
> model?

If you want to store the output to a log file or something similar,  
use the logger object (for example, logger.info).

Otherwise, there isn’t a simple way of getting HTML from the model and  
that’s because the model never speaks directly with the view. It’s the  
controller’s job to do that. If you look closely, you’ll see that you  
completely skipped the controller.

As a hint, try using scaffolds and modify one to suit your needs. It  
might give you a good head-start, but remember that sometimes you  
might have to seriously tweak them.

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [February 11, 2008, 5:49pm UTC](https://www.ruby-forum.com/t/getting-human-readable-results/128683/7 "2008-02-11T17:49:44Z")

</div>

On Feb 10, 12:39 pm, “Andrei M.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> If you want to store the output to a log file or something similar,  
> use the logger object (for example, logger.info).

Oh, I should’ve written HTML output for a user.

> Otherwise, there isn’t a simple way of getting HTML from the model and  
> that’s because the model never speaks directly with the view. It’s the  
> controller’s job to do that. If you look closely, you’ll see that you  
> completely skipped the controller.

I know ☹

> As a hint, try using scaffolds and modify one to suit your needs. It  
> might give you a good head-start, but remember that sometimes you  
> might have to seriously tweak them.

I have a scaffold for this model, I’m using rails 1.5 IIRC.

Ok, I started to do that before going this direction. I had the  
desired output through the console, but didn’t know how to translate  
that to MVC, which is the bigger question.

Basically, the model has a report method, then, in the controller  
there’s a “run\_report” method? Then the view “calls” run\_report?

Thanks,

Thufir

[http://code.google.com/p/goodfellow-tool/source/browse](http://code.google.com/p/goodfellow-tool/source/browse)

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [February 11, 2008, 2:08pm UTC](https://www.ruby-forum.com/t/getting-human-readable-results/128683/8 "2008-02-11T14:08:45Z")

</div>

On Feb 10, 9:20 am, Phlip [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
[…]

> After fixing this, you need to just sit and read a Ruby tutorial. Don’t  
> just read to answer your current question; you need soak-time with this  
> stuff to get the hang of it.

Yes, I keep going to the library looking for books to answer this sort  
of question – no luck yet. Honestly, I’ve never seen ruby tutorial  
address this sort of thing, perhaps I’m reading the wrong tutorials.

> In Rails (which this is not the best forum for), ‘puts’ never goes into a  
> web page. It always goes into the console, which is somewhere inside your  
> web server.

Right, it was just to illustrate the desired output.

> ```
> }.join('<br/>')
> end
> 
> ```
> 
> Note that I added a clear ‘return’ (I always do), and that I used 2-space  
> tabs. Your editor picks 8 because it is stupid.

Guess I’ll have to “nano --tabsize=2 foo.rb” or switch to emacs;  
another thing to learn (emacs).

Ah, yes I’ve heard about this “map” but couldn’t figure out how to use  
it. Now I’ll be able to try some more focused queries in google about  
it.

The “map” and “join” work together?

What I find most confusing about the above is the CGI part, I’ve never  
seen that in any rails book I’ve looked at, but maybe I’ve not looked  
hard enough!

> Use that like this:
> 
> > \<% @login.report.each do |report| %\>  
> > \<%= report %\>  
> > \<% end %\>
> 
> Notice I took your h out, because your system needed to escape your data  
> in between outputting your   
> .

I would’ve never known that in a million years. How do you know that  
the system needs to escape the data between outputting   
? Anytime  
data is output it must be escaped, then un-escaped, or something?

> You also need to read up on basic HTML. _All_ the Rails documentation  
> will assume you know you can’t use “\t” in a web page!

Of course 🙂

> –  
> Phlip

Is there a more ruby-ish or rails way? Somehow, I can’t think that  
\_why would do it like that, it seems kludgy.

Let me rephrase the question:

What’s the optimal technique (idiom?) for getting output from the  
model?

thanks,

Thufir

ps: Absolutely, I’ll be going more in the ruby direction than rails,  
thank you for the pointers 🙂

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [February 11, 2008, 6:35pm UTC](https://www.ruby-forum.com/t/getting-human-readable-results/128683/9 "2008-02-11T18:35:23Z")

</div>

On Feb 10, 12:37 pm, “Phlip” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > Guess I’ll have to “nano --tabsize=2 foo.rb” or switch to emacs;  
> > > another thing to learn (emacs).
> 
> Please don’t tell us you are working in Linux with only some kind of console  
> mode available…

Of course…not 😉

-Thufir
