Getting human-readable results

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

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

On Feb 10, 2:40 pm, Howard R. [email protected] 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

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

On Feb 10, 3:39 pm, Thufir [email protected] wrote:

On Feb 10, 2:40 pm, Howard R. [email protected] 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 :slight_smile:

thanks,

Thufir

On 2/10/08, Thufir [email protected] wrote:

On Feb 10, 9:20 am, Phlip [email protected] 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.

On Feb 10, 12:39 pm, “Andrei M.” [email protected] 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 :frowning:

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

On Feb 10, 9:20 am, Phlip [email protected] 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 :slight_smile:


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

On Feb 10, 12:37 pm, “Phlip” [email protected] 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 :wink:

-Thufir