page object

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

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?

*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

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?

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

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 Development with Rails (you want the 3rd edition) does a good job of introducing rails to those without prior knowledge of Ruby.

Colin