D''Andrew "Dave" Thompson
2005-Dec-31 20:17 UTC
[Rails] [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 "Dave" Thompson http://dathompson.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20051231/f082a5e3/attachment.html
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:> 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 "Dave" Thompson > http://dathompson.blogspot.com > _______________________________________________ > 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
D''Andrew "Dave" Thompson
2005-Dec-31 22:07 UTC
[Rails] [Model] [Noob] Table Naming w/ underscores
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
On 12/31/05, Derek Haynes <derek.haynes@highgroove.com>
wrote:>
> 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:
> > 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 "Dave" Thompson
> > http://dathompson.blogspot.com
> > _______________________________________________
> > 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
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
~~~~~~~~~~~~~~~~~~~
D''Andrew "Dave" Thompson
http://dathompson.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20051231/665ac655/attachment.html
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, DaveThat''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 -- Posted via http://www.ruby-forum.com/.