newbie: Rails deliberations

P

peter.cutting

I have alot of questions and (daft) opinions which I will place in this
thread and hopefully I will get some answers. Thanks alot. Peter

1) is the "list" really necessary in the following code example taken
from
http://dev.rubyonrails.org/svn/rails/trunk/actionpack/lib/action_controller/scaffolding.rb
# def list
# @entries = Entry.find_all
# render_scaffold "list"
# end

2) It would be nice if the command
ruby script\generate scaffold <model>
also embedded comments in the generated code which described what name
is what how the name variations are related to one another. Superfluous
for the experts, I know. But since the code is so tight already why not
give the newbies some help

3) 2) is especially important since the naming is a bit of nightmare.
eg all sorts of implicit messing around with leading capitals,
camelcase, underscores, pluralisations, and other (eg person->people)
transformations going on. This is all very difficult for mere mortals
(with shitty memories) to grok

4) what is going on with new and create. Do they work togeather. If so
how?
(example taken from same place as above)
# def new
# @entry = Entry.new
# render_scaffold
# end
#
# def create
# @entry = Entry.new(@params["entry"])
# if @entry.save
# flash["notice"] = "Entry was succesfully created"
# redirect_to :action => "list"
# else
# render "entry/new"
# end
# end

5) What is going on in the generated edit view template?
<%= error_messages_for 'project' %>
<%= form 'project', :action => 'update' %>

The error_messages_for bit I dont understand at all.
Editing a record initiates the edit action which which default renders
the edit view which seems to (based on the above) start of a update
action ??? and now I am lost

6) the list template scaffolding iterates thru columns. Wouldnt it be
better to inline the columns since they will almost certainly be
customised later. A lot easier to read and mess about with. (the
iterated alternative could also be included but switched off and the
developer could then quickly switch it on to see all the available
columns).

<% for project in @projects %>
<tr>
<% for column in Project.content_columns %>
<td><%=h project[column.name] %></td>

Thats enough for now.
 
J

James G. Britt

I have alot of questions and (daft) opinions which I will place in this
thread and hopefully I will get some answers. Thanks alot. Peter

I don't mean to discourage you from posting Rails questions here, but
have you asked these questions on the Rails mailing list?

http://lists.rubyonrails.org/mailman/listinfo/rails

It seems many of your questions are about Rails' design decisions and
implementation details, and I think you would get better, faster
answers on the Rails list.

James
 
E

Eric Hodel

--Apple-Mail-41-215164423
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed

I have alot of questions and (daft) opinions which I will place in this
thread and hopefully I will get some answers. Thanks alot. Peter

1) is the "list" really necessary in the following code example taken
from
http://dev.rubyonrails.org/svn/rails/trunk/actionpack/lib/
action_controller/scaffolding.rb
# def list
# @entries = Entry.find_all
# render_scaffold "list"
# end

Yes.

It would be more code to 'guess' which scaffold you wanted from caller.
And it would also get in your way more than you like.
2) It would be nice if the command
ruby script\generate scaffold <model>
also embedded comments in the generated code which described what name
is what how the name variations are related to one another. Superfluous
for the experts, I know. But since the code is so tight already why not
give the newbies some help

Have you read anything from http://api.rubyonrails.com? Lots of this
code is very well described there.
3) 2) is especially important since the naming is a bit of nightmare.
eg all sorts of implicit messing around with leading capitals,
camelcase, underscores, pluralisations, and other (eg person->people)
transformations going on. This is all very difficult for mere mortals
(with shitty memories) to grok

Have you read:

http://rails.rubyonrails.com/files/vendor/actionpack/README.html
http://rails.rubyonrails.com/files/vendor/activerecord/README.html
4) what is going on with new and create. Do they work togeather. If so
how?
(example taken from same place as above)
# def new
# @entry = Entry.new
# render_scaffold
# end
#
# def create
# @entry = Entry.new(@params["entry"])
# if @entry.save
# flash["notice"] = "Entry was succesfully created"
# redirect_to :action => "list"
# else
# render "entry/new"
# end
# end

ActionController methods are 'actions'...
5) What is going on in the generated edit view template?
<%= error_messages_for 'project' %>
<%= form 'project', :action => 'update' %>

So this form will be sent to the 'update' action of the current
controller.
The error_messages_for bit I dont understand at all.

Well documented on http://api.rubyonrails.com:

http://rails.rubyonrails.com/classes/ActionView/Helpers/
ActiveRecordHelper.html#M000236
Editing a record initiates the edit action which which default renders
the edit view which seems to (based on the above) start of a update
action ??? and now I am lost

When you submit the form, yes. See the documentation for #url_for,
which is how Rails generates URLs:

http://rails.rubyonrails.com/classes/ActionController/Base.html#M000079
6) the list template scaffolding iterates thru columns. Wouldnt it be
better to inline the columns since they will almost certainly be
customised later. A lot easier to read and mess about with. (the
iterated alternative could also be included but switched off and the
developer could then quickly switch it on to see all the available
columns).

Sure, go nuts!

Just displaying the columns is 'good enough' because the second thing I
do after adding a scaffolded controller is rip away all the scaffolding
and build something sensible with only the columns I need. (The first
being adding some good data to play with.)

Rails does all the heavy lifting you don't want to do, and leaves you
to do the heavy lifting you *should* be doing.

--
Eric Hodel - (e-mail address removed) - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

--Apple-Mail-41-215164423
content-type: application/pgp-signature; x-mac-type=70674453;
name=PGP.sig
content-description: This is a digitally signed message part
content-disposition: inline; filename=PGP.sig
content-transfer-encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)

iD8DBQFCASV3MypVHHlsnwQRAnDUAJwLdchVypF+psmEVrNVmcRAqvfE9wCg5FSV
5uz96xXB5r6cFnbYkKotU1w=
=lqJP
-----END PGP SIGNATURE-----

--Apple-Mail-41-215164423--
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top