[Model] [Noob] Table Naming w/ underscores

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

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_em[email protected] wrote:

returning a nill object at the moment.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Derek H.
HighGroove Studios - http://www.highgroove.com
Atlanta, GA
Keeping it Simple.
404.593.4879

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs