1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-19 06:58:02 +00:00

Compare commits

...

3 Commits

Author SHA1 Message Date
nick-w-nick
a4aec89c76 Merge 295fe153ad into 2e72ec1160 2024-09-23 09:56:17 -04:00
jbranchaud
2e72ec1160 Add Generate A Model as a Rails TIL 2024-09-20 20:54:52 -05:00
nick-w-nick
295fe153ad added mention of ES6 compatibility
Hello, I've added a small blockquote below the description to indicate that this method of accessing an indefinite number of function arguments has been superseded by the use of the spread operator via rest parameters for ES6+ compatibility.
2022-01-06 11:39:04 -05:00
3 changed files with 30 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
_1441 TILs and counting..._
_1442 TILs and counting..._
---
@@ -897,6 +897,7 @@ _1441 TILs and counting..._
- [Find Or Create A Record With FactoryBot](rails/find-or-create-a-record-with-factory-bot.md)
- [Find Records With Multiple Associated Records](rails/find-records-with-multiple-associated-records.md)
- [Force All Users To Sign Out](rails/force-all-users-to-sign-out.md)
- [Generate A Model](rails/generate-a-model.md)
- [Generate A Rails App From The Main Branch](rails/generate-a-rails-app-from-the-main-branch.md)
- [Generating And Executing SQL](rails/generating-and-executing-sql.md)
- [Get A Quick Approximate Count Of A Large Table](rails/get-a-quick-approximate-count-of-a-large-table.md)

View File

@@ -5,6 +5,8 @@ an array-like object with all of the arguments to the function. Even if not
all of the arguments are referenced in the function signature, they can
still be accessed via the `arguments` object.
> For ES6+ compatibility, the `spread` operator used via [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters) is preferred over the `arugments` object when accessing an abritrary number of function arguments.
```javascript
function argTest(one) {
console.log(one);

26
rails/generate-a-model.md Normal file
View File

@@ -0,0 +1,26 @@
# Generate A Model
The `rails` CLI comes with a variety of generators. Perhaps the mostly common
one to use is the _model_ generator.
The model generator will create a migration and a model file for the entity
that you name. In the following example `Book` will result in a
`app/models/book.rb` file as well as a migration file for a `books` table.
These generators know the singular and plural conventions.
At the end of the command is a series of field definitions containing the field
_name_ and field _type_. These are used in the migration file for defining
columns on the new table.
```bash
bin/rails generate model Book title:string publication_date:date author:string
invoke active_record
create db/migrate/20240920223447_create_books.rb
create app/models/book.rb
invoke rspec
create spec/models/book_spec.rb
```
You may also notice that an `rspec` action was invoked as part of this
generator. That is because I have the `rspec-rails` gem in my project. That gem
hooks into the model generator so that a model spec also gets generated. Handy!