Newby syntax question

  • Thread starter Achim Domma (SyynX Solutions GmbH)
  • Start date
A

Achim Domma (SyynX Solutions GmbH)

Hi,

I try to learn Rails and Ruby in parallel. I've read in 'Programing
Ruby' about methods, objects, ... but now I have a question. Here's the
code snippet from 'Rolling with Ruby ...':

class RecipeController < ApplicationController
scaffold :recipe
end

What exactly is 'scaffold' in this case? A class method of
ApplicationController? Does this method manipulate the RecipeController
class somehow? Or am I on the complete wrong way?

regards,
Achim
 
T

Tomas Landin

Achim said:
What exactly is 'scaffold' in this case? A class method of
ApplicationController? Does this method manipulate the RecipeController
class somehow? Or am I on the complete wrong way?

scaffold is, according to http://api.rubyonrails.com/ a public instance
method of ActionController::Scaffolding::ClassMethods.

The RDoc page can be found here:
http://api.rubyonrails.com/classes/ActionController/Scaffolding/ClassMethods.html

What it does is it adds a number of instance methods to the controller
class from where you call it. In this case, RecipeController.
 
C

Christophe Grandsire

Selon "Achim Domma (SyynX Solutions GmbH) said:
class RecipeController < ApplicationController
scaffold :recipe
end

What exactly is 'scaffold' in this case? A class method of
ApplicationController?

Spot on! Notice though that it's also a class method of RecipeController.=
Class
methods also get inherited. And it's as class method of RecipeController =
that
it works here.

Does this method manipulate the RecipeController
class somehow?

Note that I am not very knowledgeable about Rails (I'm probably one of th=
e few
Rubyists that has not tried his hand at it yet ;) ), but if I remember
correctly it does, creating various instance methods of RecipeController =
for
the creating, modifying, accessing and erasing of recipe records (put a b=
ig
AFAIK behind that).

It's basically like attr_accessor, which is also a class method (actually
defined in Module) and also takes a symbol. Something like:

class Foo
attr_accessor :foo
end

just creates two methods "foo" and "foo=3D" to access and modify the cont=
ents of
the instance variable @foo it also created for the occasion :) .

Or am I on the complete wrong way?
On the contrary, you were extremely close.
--
Christophe Grandsire.

http://rainbow.conlang.free.fr

It takes a straight mind to create a twisted conlang.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top