Forum: Ruby on Rails page object

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Matt S. (Guest)
on 2009-05-31 06:31
(Received via mailing list)
Hello,

I'm new to the group, and still learning rails. I am a C++ programmer
by trade, so I'm finding some of the rails semantics confusing. When I
come accross a statement like this:

<%= link_to_function "clickme" do |page| ...

... and then a few lines that I do understand, could someone explain
to me the following: the link_to_function function takes some object
for the rendered link, and then what? it's supposed to be *args, and
then &block. I assume that the code that comes afterward is the
reference to a block of text, but how does the args part work? Also,
in this instance, how does the do evaluate |page|? and last: where in
the rails API docs is the reference for the page object?

I'm sure someone well versed in ruby can explain this to me. Thankyou
for any help. Even links to documentation that explains these ruby
operators would help. Thanks again,

Matt
Frederick C. (Guest)
on 2009-05-31 06:37
(Received via mailing list)
On May 31, 1:41 am, Matt S. <removed_email_address@domain.invalid> wrote:
> for the rendered link, and then what? it's supposed to be *args, and
> then &block. I assume that the code that comes afterward is the
> reference to a block of text, but how does the args part work? Also,
> in this instance, how does the do evaluate |page|? and last: where in
> the rails API docs is the reference for the page object?

*args means that you can pass it as many arguments as you want (and if
you were writing such a function then args would be an array
containing those options). That doesn't necessarily mean that the
function will do something sensible if you pass it 23 arguments (to
know that you need to read the docs for it)

&block is basically just the block you give the function (and the fact
that it's there in the docs is probably a bit of an artefact of rdoc -
you can pass a block to any method (again, no guarantees on what that
method will do with it). The 'do' doesn't evaluate page, that's just
you giving a name to the object that link_to_function yields to you
(which is an instance of JavaScriptGenerator or something similar).

You might find it easier to get a solid grounding in ruby first before
starting to fiddle around with rails.

Fred
Colin L. (Guest)
on 2009-05-31 11:43
(Received via mailing list)
2009/5/31 Frederick C. <removed_email_address@domain.invalid>:
>> <%= link_to_function "clickme" do |page| ...
> you were writing such a function then args would be an array
>
> You might find it easier to get a solid grounding in ruby first before
> starting to fiddle around with rails.

I would not say that is necessary to get a 'solid' grounding in Ruby
before fiddling with Rails.  I successfully got going with my
fiddling, learning both at the same time. (Though I continue to make
errors in both areas of course).  The book Agile Web D. with
Rails (you want the 3rd edition) does a good job of introducing rails
to those without prior knowledge of Ruby.

Colin
This topic is locked and can not be replied to.