Reputation: 61
When dealing with resources (e.g. users) different parts of the rails app refer to them in one of several ways, some capitalized/singular, some lowercase/plural etc. At times this seems logical (e.g. a method for several resources vs. just one) but at other times it seems arbitrary...
Is there any easy way of remembering how to access them from different parts of the app?
Upvotes: 0
Views: 579
Reputation: 17802
Most of the time, you will need to access different models across the app. And you would always access them with singular name with first letter uppercase'd like User
, Tweet
. Regarding controllers, I don't think so you would ever to access a controller from some other controller.
Remember, if are using raw SQL, and you want to access the table of a model, that would always be in plural and all lower case, like users
for User
, and tweets
for Tweet
.
Regarding routes, they are always accessed through lowercase words, and deciding whether singular or plural -- it depends upon the context.
If you are accessing all tweets, the route method will be tweets_path
, and if want one tweet, then tweet_path(1)
or edit_tweet_path(1)
where 1
being the id
of the tweet that you want to show or edit.
And for classes: everywhere in Rails, and generally speaking in Ruby, they would always be singular, and uppercase'd.
Upvotes: 2