0

I am creating a site that will sell phones and I have tables and products all set up.

When I run:

rails generate Scaffold Sale item_id:integer employee_id:integer

I get a Ruby file called 'Sale' and 'Part.rb' in my app/models. I am not getting the two Ruby files I need, which are 'Emlployee.rb' and 'Item.rb'.

I need these files in order to keep track of which employee sold which phone. When I navigate to my site /sales there is a table but when I navigate to /employees to add a new employee Cloud0 tells me path is unspecified.

What am I doing wrong?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
John Doe
  • 17
  • 4
  • You aren't doing anything wrong, `rails generate scaffold sale` only generates the model etc. for sale. Specifying `item_id:integer` includes the `item_id` field on the `sales` table so you can use an association, but the `Item` and `Employee` models must be created separately. – mikej May 02 '17 at 20:47
  • If you refer to a previous question you need to provide a link. But your question should be stand-alone because SO questions are not threads, they are articles. Your expertise or experience isn't important to us, and mentioning it is merely distracting. Read "[How To Ask Questions The Smart Way](http://catb.org/esr/faqs/smart-questions.html)" and Jon Skeet's "[Writing the perfect question](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/)" to learn what we need. – the Tin Man May 02 '17 at 21:03

1 Answers1

0
rails generate scaffold Sale item_id:integer employee_id:integer

Only creates the stuff that belongs to the Sale. So, in your case with this command you created a Sale.rb model that has two attributes - item_id and employee_id (scaffold creates also it's assets, controller, routes and tests).

If you need to create also Employee and Item models, you'll need to create them separately.

> rails g model Employee
> rails g model Item

Read also the difference between scaffold and model in Rails and the documentation about the generate command.

Community
  • 1
  • 1
Vucko
  • 20,555
  • 10
  • 56
  • 107