Ruby on Rails - model from generate scaffold command

user3064141

I used "rails generate scaffold Post title:string body:text" to create a model and related controller etc. I was surprised to find the model and controller files empty. I thought the model file would contain instance variables to store each post's title and body attributes. Can someone explain to me why the Post model file running generate scaffold is empty even though the data items do show up in the database. When I bring up the webpage and go to the .../posts url I can see the json listing of the ones I created. Thanks.

hashrocket

Models are Ruby classes. They talk to the database, store and validate data, perform the business logic and otherwise do the heavy lifting.

Controllers do the work of parsing user requests, data submissions, cookies, sessions and the “browser stuff”.

The reason your model is empty is because Rails doesn't know what you want your models to do. It knows you want basic CRUD functionality, so it fills in your controllers accordingly.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to run `rails generate scaffold` when the model already exists?

"rails generate model" hangs

Ruby On Rails scaffold need to include foreign keys?

Generate scaffold which references a model who refers another model

Accessing data from model in Ruby on rails app

"rails generate scaffold" error on "_from.erb" (jbuilder issue?)

Ruby on Rails: Increase value of object in scaffold with button_to

Brand new rails app, can't generate scaffold

Can EFCore Scaffold-DbContext generate custom Model names?

Generate array of textbox in Ruby on Rails

Ruby on Rails Model association

NoMethodError when using "rails generate scaffold"

Ruby on Rails - add fields from a Model on another Model's form

Ruby on Rails: finding a model instance from a different controller

Ruby on Rails create model attribute with options to select from

Access a instance method from other model in ruby on rails?

Generate parameters in ruby on rails

rails scaffold not plural generate

Ruby on Rails - cannot run the following command : rails generate rspec:install

Ruby on Rails - model validation

Ruby On Rails : How to undo nested_scaffold in rails

Raise an error on Ruby/Script generate scaffold

Error validations from child model Ruby on Rails

Ruby on Rails: Replace values in array with hash values (from database model)

Ruby on rails, changing recently created scaffold

Ruby On Rails: Accessing value from associated model

Ruby on Rails - rails g scaffold foreign key

Generate scaffold for multiple namespaces using same migration and model on rails 6

How to generate .yml file from Ruby on Rails?