firstdraft / draft_generators

Rails generators that help beginners learn to program.
MIT License
2 stars 3 forks source link

Pm resource variable naming #87

Closed pmckernin closed 4 years ago

pmckernin commented 4 years ago

I edited the draft generators to follow the convention talked about in issue #86. I went with the_class for a single record and list_of_classes for a group of records. The one change that I made was to go with one_record in place of a_record so we wouldn't have to deal with an "a" or "an" situation. I did find a method we could use to address this if we agree that a is better than one.

raghubetina commented 4 years ago

@pmckernin Great! I think I do prefer a_, though. Which method were you thinking? I seem to recall using a gem in the past, but it would be nice if we didn't have to pull in a dependency, if it's included in Ruby or ActiveSupport now.

raghubetina commented 4 years ago

@pmckernin Oh, uh oh. Sad news — it looks like branched off of master. Usually, that is what you should do. In this case, we've left master untouched for years because that's what ideas.firstdraft.com uses to generate code and we don't want to mess with that (this will soon change, as we've created a separate gem for Ideas 2.0).

So basically, the winter-2020 branch is the "master" branch of draft_generators for AppDev. You should branch off of that branch.

raghubetina commented 4 years ago

The new style I've been using for querying, with an intermediate variable for the result of .where, seems to help with the whole Relation/pluck/at issues. So let's codify that into draft:resource as well?

For show, et al,

the_id = params.fetch("path_id")
matching_whatevers = Whatever.where({ :id => the_id })
@the_whatever = matching_whatevers.at(0)

For index, et al,

matching_whatevers = Whatever.all
@list_of_whatevers = matching_whatevers.order({ :created_at => :desc })

Thoughts @pmckernin @jelaniwoods?

jelaniwoods commented 4 years ago

@pmckernin Great! I think I do prefer a_, though. Which method were you thinking? I seem to recall using a gem in the past, but it would be nice if we didn't have to pull in a dependency, if it's included in Ruby or ActiveSupport now.

@pmckernin It's not too hard to add a helper method that finds the correct indefinite article to use. There's a stackoverflow question with more info here.

pmckernin commented 4 years ago

@pmckernin Great! I think I do prefer a_, though. Which method were you thinking? I seem to recall using a gem in the past, but it would be nice if we didn't have to pull in a dependency, if it's included in Ruby or ActiveSupport now.

@pmckernin It's not too hard to add a helper method that finds the correct indefinite article to use. There's a stackoverflow question with more info here.

Yep, this is the one I was looking at.

raghubetina commented 4 years ago

@pmckernin Great! I think I do prefer a_, though. Which method were you thinking? I seem to recall using a gem in the past, but it would be nice if we didn't have to pull in a dependency, if it's included in Ruby or ActiveSupport now.

@pmckernin It's not too hard to add a helper method that finds the correct indefinite article to use. There's a stackoverflow question with more info here.

The gem linked in that thread is the one I usually use. Takes care of at least some corner cases (like "university").