# \[Model\] \[Noob\] Table Naming w/ underscores

**URL:** <https://www.ruby-forum.com/t/model-noob-table-naming-w-underscores/51466>\
**Category:** Rails\
**Created:** [December 31, 2005, 9:18pm UTC](https://www.ruby-forum.com/t/model-noob-table-naming-w-underscores/51466 "2005-12-31T21:18:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DSAndrew\_SDaveSS\_Th](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3da27b/32.png) [@DSAndrew\_SDaveSS\_Th](https://www.ruby-forum.com/u/DSAndrew_SDaveSS_Th)\
**Post date:** [December 31, 2005, 9:18pm UTC](https://www.ruby-forum.com/t/model-noob-table-naming-w-underscores/51466/1 "2005-12-31T21:18:02Z")

</div>

Greetings:

I am writing a basic accounting module for an app. Rather unfortunately  
the  
name “transactions” is a reserved term in Rails (being the only  
accounting  
term trully representational of a financial transaction). I am left to  
come  
up with other names. One such name was f\_transaction.

This worked on the DB level, but I noticed that the Model name dropped  
the  
underscore, thus “FTransaction”. How do I refer to the model in the view  
layer? Do I use f\_transaction, ftransaction? Either way it is currently  
returning a nill object at the moment.

Along the same naming issue, when defining a method  
“recent\_ftransactions”  
how does the naming work here too (re: underscoring)?

Thanks, Dave

---

<div class="post-metadata">

**Author:** ![DSAndrew\_SDaveSS\_Th](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3da27b/32.png) [@DSAndrew\_SDaveSS\_Th](https://www.ruby-forum.com/u/DSAndrew_SDaveSS_Th)\
**Post date:** [December 31, 2005, 10:03pm UTC](https://www.ruby-forum.com/t/model-noob-table-naming-w-underscores/51466/2 "2005-12-31T22:03:08Z")

</div>

D’Andrew,

> How do I refer to the model in the view  
> layer? Do I use f\_transaction, ftransaction?

Use FTransaction (the name of the class):  
FTransaction.find(12) \<\< - Find the transaction with an id of 12.

> Along the same naming issue, when defining a method “recent\_ftransactions”  
> how does the naming work here too (re: underscoring)?

Just keep your method names all lowercase. It doesn’t matter what you  
name your methods. So yes, #recent\_ftransactions would work.

- Derek

On 12/31/05, D’Andrew Dave T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> returning a nill object at the moment.
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Derek H.  
HighGroove Studios - [http://www.highgroove.com](http://www.highgroove.com)  
Atlanta, GA  
Keeping it Simple.  
404.593.4879

---

<div class="post-metadata">

**Author:** ![DSAndrew\_SDaveSS\_Th](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3da27b/32.png) [@DSAndrew\_SDaveSS\_Th](https://www.ruby-forum.com/u/DSAndrew_SDaveSS_Th)\
**Post date:** [December 31, 2005, 11:09pm UTC](https://www.ruby-forum.com/t/model-noob-table-naming-w-underscores/51466/3 "2005-12-31T23:09:14Z")

</div>

So would this be the “conventional” naming pattern?

DB Table: fiscal\_transactions (model\_names)  
Model: fiscal\_transaction (model\_name)  
Class: FiscalTransaction (ModelName)  
Controller: fiscal\_transactions (model\_names)  
View Reference: (as follows)

\<% for fiscal\_transaction in @fiscal\_transactions %\>  
\<%= fiscal\_transaction.amount %\>\</html stuff\>  
\<% end %\>

Thanks again, Dave

---

<div class="post-metadata">

**Author:** ![DSAndrew\_SDaveSS\_Th](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3da27b/32.png) [@DSAndrew\_SDaveSS\_Th](https://www.ruby-forum.com/u/DSAndrew_SDaveSS_Th)\
**Post date:** [December 31, 2005, 11:37pm UTC](https://www.ruby-forum.com/t/model-noob-table-naming-w-underscores/51466/4 "2005-12-31T23:37:47Z")

</div>

D’Andrew “Dave” Thompson wrote:

> So would this be the “conventional” naming pattern?
> 
> DB Table: fiscal\_transactions (model\_names)  
> Model: fiscal\_transaction (model\_name)  
> Class: FiscalTransaction (ModelName)  
> Controller: fiscal\_transactions (model\_names)  
> View Reference: (as follows)
> 
> \<% for fiscal\_transaction in @fiscal\_transactions %\>  
> \<%= fiscal\_transaction.amount %\>\</html stuff\>  
> \<% end %\>
> 
> Thanks again, Dave

That’s 99% right. The Controller class would probably be called  
FiscalTransactionController, and it would reside in a file named  
fiscal\_transaction\_controller.rb.

Also, as for the loop, I’ve seen the following to be more traditional:

\<% @fiscal\_transactions.each do |fiscal\_transaction| %\>

and since you can name the parameter anything you want, you could reduce  
it to

\<% @fiscal\_transactions.each do |t| %\>

if you’re looking for brevity. But it’s all syntactic sugar, your way  
is just as good.

Jeff
