# About RAILS

**URL:** <https://www.ruby-forum.com/t/about-rails/145965>\
**Category:** Ruby\
**Created:** [August 15, 2008, 4:10pm UTC](https://www.ruby-forum.com/t/about-rails/145965 "2008-08-15T16:10:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexandre\_Brillant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b19c9b/32.png) [@Alexandre\_Brillant](https://www.ruby-forum.com/u/Alexandre_Brillant)\
**Post date:** [August 15, 2008, 4:10pm UTC](https://www.ruby-forum.com/t/about-rails/145965/1 "2008-08-15T16:10:57Z")

</div>

Hi,

I don’t understand one point with Ruby on Rails :

I have the following migration file :  
class Personne \< ActiveRecord::Migration

def self.up

# Commentaire à enlever si vous avez déjà une table personnes

# drop\_table :personnes

create\_table( :personnes ) {

|p|

p.string :prenom

p.string :nom

p.string :telephone

p.text :adresse

}

end

def self.down

drop\_table :personnes

end

end

* * *

My model is very simple :

class Personne \< ActiveRecord::Base

end

* * *

In my controller, I put the following code :

class CarnetController \< ApplicationController

def voir

# Find all the objet Personne from the table personnes

@personnes = Personne.find(:all)

end

end

And it works, but I don’t understand how Rails can know that the classe  
Personne should be mapped to the

personnes table. Where it is stored ?

Txa lot !

---

<div class="post-metadata">

**Author:** ![Alexandre\_Brillant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b19c9b/32.png) [@Alexandre\_Brillant](https://www.ruby-forum.com/u/Alexandre_Brillant)\
**Post date:** [August 15, 2008, 4:27pm UTC](https://www.ruby-forum.com/t/about-rails/145965/2 "2008-08-15T16:27:25Z")

</div>

Alexandre Brillant wrote:

> I don’t understand one point with Ruby on Rails :

The best place to discuss RoR is here:

[http://groups.google.com/group/rubyonrails-talk/](http://groups.google.com/group/rubyonrails-talk/)

This forum is only qualified to discuss Ruby, the language behind Rails,  
and  
many other awesome programs.

> create\_table( :personnes ) {
> 
> |p|

I don’t know what editor you use, but ‘script/generate model’ should  
have  
created better syntax there. The |p| should be up near the {, as a style  
thing.  
And your editor might have inserted linefeeds when you tried to paste  
your  
source here.

I would scratch this project and use ‘script/generate model’ to redo the  
files.

> And it works, but I don’t understand how Rails can know that the classe  
> Personne should be mapped to the
> 
> personnes table. Where it is stored ?

Google for “convention over configuration”. Then pity the programmers,  
using  
other platforms, who must edit ~1 Kb of lines of configuration files,  
just to  
stitch things together!

By default, ActiveRecord will read the name of your class, Personne,  
lower-case  
it, personne, and pluralize it: personnes. Then it looks for that table.

It uses a class called Inflector to do this.

However, I suspect you are lucky to use a language that pluralizes with  
an s. I  
don’t think the Inflector is smart enough to divine your language and  
pluralize  
with its conventions - if any! Maybe someone on the RoR forum knows how  
to set  
your locale to French, to handle French idioms correctly…

---

<div class="post-metadata">

**Author:** ![Alexandre\_Brillant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b19c9b/32.png) [@Alexandre\_Brillant](https://www.ruby-forum.com/u/Alexandre_Brillant)\
**Post date:** [August 15, 2008, 4:42pm UTC](https://www.ruby-forum.com/t/about-rails/145965/3 "2008-08-15T16:42:40Z")

</div>

Tx philip, I will go to the google forum.

Well for the |p| after this is correct from the syntax point of view,

create\_table( … ) { |p|

or

create\_table( … ) {  
|p|

are both ok, I prefer the second one

“Phlip” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) a écrit dans le message de news:  
ljgpk.17941$removed\_email\_address@domain.invalid…

---

<div class="post-metadata">

**Author:** ![Alexandre\_Brillant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b19c9b/32.png) [@Alexandre\_Brillant](https://www.ruby-forum.com/u/Alexandre_Brillant)\
**Post date:** [August 15, 2008, 5:05pm UTC](https://www.ruby-forum.com/t/about-rails/145965/4 "2008-08-15T17:05:32Z")

</div>

Thank you for the generate model command, I will try it to see the  
result.

Thank you too for the remark about the multi-lines do end idiom.

🙂

“Phlip” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) a écrit dans le message de news:  
ELgpk.17949$removed\_email\_address@domain.invalid…

---

<div class="post-metadata">

**Author:** ![Alexandre\_Brillant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b19c9b/32.png) [@Alexandre\_Brillant](https://www.ruby-forum.com/u/Alexandre_Brillant)\
**Post date:** [August 15, 2008, 4:55pm UTC](https://www.ruby-forum.com/t/about-rails/145965/5 "2008-08-15T16:55:35Z")

</div>

Alexandre Brillant wrote:

> are both ok, I prefer the second one

I prefer the output of script/generate model, because it gets so much  
ready for  
you all at once. For example, it also creates matching test suites and  
fixtures.

Also, you will learn that all languages come with established styles.  
For  
example, “everyone” typically writes a one-liner block with {}, but they  
write a  
multi-line block with do-end.

Knowing why and how people use different Ruby idioms will help you match  
your  
style to your team’s style, if any. And it will help you break that  
style when  
you know _why_ you are breaking it.
