Thufir Hawat
2/10/2008 8:03:00 PM
On Feb 10, 9:20 am, Phlip <phlip2...@gmail.com> 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.
> Next, Ruby uses a "magic return" system, where the return value of a
> function is the return of its last block. 'calls.each' returns 'calls',
> for method-chaining (look that up). You need to make a 'map' of report
> contents, then 'join' them together, like this:
>
> def report
> return calls.map{ |call|
> CGI::escapeHTML(login) + "\t" +
> call.created_at.to_s + "\t"
> CGI::escapeHTML(call.comment)
> }.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 <br/>.
I would've never known that in a million years. How do you know that
the system needs to escape the data between outputting <br/>? 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 :)