Sorry if you’ve seen this before. I didn’t get a response from the
original post. Because this is such a high volume list, posts < 1 day
old don’t tend to not get responses. ( or, maybe I’m just too
impatient
I’m trying to understand how the Rails scaffold generator works well
enough that I can teach it to write Markaby files. Most of the
templates were easy, but I’m having problems with the form templates.
The template/form.rhtml file refers to
<%= template_for_inclusion%>
I’m guessing that ‘template_for’ is a method and ‘inclusion’ is a
variable. Where does this variable come from? How can I tell where it
gets referenced/populated?
How do the ’
’ tags get generated? I don’t see
them in any of the scaffold_generator files.
What does ‘lamda(method_name)’ do? Is it saying: ‘include the
output from method_name here’ ?
–
Best Regards,
-Larry
“Work, work, work…there is no satisfactory alternative.”
— E.Taft Benson
I’m trying to understand how the Rails scaffold generator works well
enough that I can teach it to write Markaby files. Most of the
templates were easy, but I’m having problems with the form templates.
I have not delved into the scaffold generator code before, but I think
I can answer some of these questions.
The template/form.rhtml file refers to
<%= template_for_inclusion%>
I’m guessing that ‘template_for’ is a method and ‘inclusion’ is a
variable. Where does this variable come from? How can I tell where it
gets referenced/populated?
No, ‘template_for_inclusion’ is all one word, so it’s either a local
variable or a method call.
A search for ‘template_for_inclusion’ suggests that it’s assigned in
line 284 of rails_generator/commands.rb:
That hash then gets turned into local variables in the template with
these lines (272-274) in command.rb:
vars = template_options[:assigns] || {}
b = binding
vars.each { |k,v| eval “#{k} = vars[:#{k}] || vars[’#{k}’]”, b }
and that’s where your local variable template_for_inclusion comes from.
How do the ’
’ tags get generated? I don’t see
them in any of the scaffold_generator files.
I can’t see any
or tags in the form view. The only
table I can find is in the list view, and that template is defined in
view_list.rhtml.
What does ‘lamda(method_name)’ do? Is it saying: ‘include the
output from method_name here’ ?
No. I’m guessing you’re looking at this line in scaffold_generator.rb:
:sandbox => lambda { create_sandbox }
Calling “lambda {some_code}” creates a new Proc object. It sort of
encapsulates that code along with the current context (i.e. the current
local variables) and lets you call it later. So in this line (line 106)
in commands.rb:
and that’s where your local variable template_for_inclusion comes from.
How do the ’ ’ tags get generated? I don’t see
them in any of the scaffold_generator files.
I can’t see any
or tags in the form view. The only
table I can find is in the list view, and that template is defined in
view_list.rhtml.
I couldn’t find them either, I did see the table row tags. When the
_form .rhtml file is generated, the form partial is magically wrapped
in
tags.
in commands.rb:
into some pretty deep Ruby (and Rails!) here, and a pickaxe would help.
I have AWDwR 1 and 2.beta. I’ll look up that reference. I also am
going through Ruby 4 Rails. Was just reading about Proc’s yesterday.
I’ll reread it with what you said in mind.
-Larry
Chris
–
Best Regards,
-Larry
“Work, work, work…there is no satisfactory alternative.”
— E.Taft Benson