Forum: Ruby on Rails [Model] [Noob] Table Naming w/ underscores

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C4edcb52652d2b17fe2b38ef13bae729?d=identicon&s=25 D'Andrew "Dave" Thompson (Guest)
on 2005-12-31 21:18
(Received via mailing list)
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
Da2dbf48d2f400ccff8f0df127798451?d=identicon&s=25 Derek Haynes (Guest)
on 2005-12-31 22:03
(Received via mailing list)
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 Thompson <dandrew.thompson@gmail.com> wrote:
> returning a nill object at the moment.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>


--
Derek Haynes
HighGroove Studios - http://www.highgroove.com
Atlanta, GA
Keeping it Simple.
404.593.4879
C4edcb52652d2b17fe2b38ef13bae729?d=identicon&s=25 D'Andrew "Dave" Thompson (Guest)
on 2005-12-31 23:09
(Received via mailing list)
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 %>
    <html stuff><%= fiscal_transaction.amount %></html stuff>
<% end %>

Thanks again, Dave
8217faf2bfdfa7daf10135d41ddd421e?d=identicon&s=25 Jeff Cohen (jeff)
on 2005-12-31 23:37
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 %>
>     <html stuff><%= 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 topic is locked and can not be replied to.