mabounassif
mabounassif

Reputation: 2341

scaffold generation

Here's an excerpt from the Ruby On rails The pragmatic Programmers:

The following command doesn't work on the new Rails, in the script folder I only have the file Rail.

ruby script/generate scaffold Product Admin (Product: Model and Admin: Controller)

The closest I can get to this instruction is using the following:

rail generate scaffold Product Admin:controller

but what I get is Product being the controller and Admin isn't anything.

How can I generate scaffold Product Admin, Product being the model and Admin being the controller with the new Rails?

Upvotes: 1

Views: 1507

Answers (4)

dhampik
dhampik

Reputation: 144

There are definetly some troubles with admin scaffold generating in Rails. The point of the quesiton is that default rails scaffold generator creates namespaced resources, including namespaced model and that is not very useful, cause models are typically common for admin area and public area.

I also faced this problem and found no standard solution for that.

So, I created rails-admin-scaffold gem (for now it's Rails 4 only) which automates this process and wrote an article with more detailed explanation. Though my answer is little outdated, it might help for other people to find suitable solution.

Upvotes: 0

elithrar
elithrar

Reputation: 24250

What version of the book do you have? It sounds like you have the 3rd Edition (Rails 2.x) and that you're using Rails 3 on your machine, which would explain the script/generate vs. rails generate scaffold inconsistencies.

Upvotes: 1

polarblau
polarblau

Reputation: 17734

If you really want to use scaffolding for this, I'd suggest to rename your controller (file + class name). But consider if e.g. an admin namespace might not do what you want.

Your structure will become somewhat harder to understand, if your controller is called admin controller and the model product, since you'd have to access the resource like this

/admin/     # -> returns all products
/admin/new  # -> form for new product
/admin/23   # -> product with id 23

See what I mean?

Upvotes: 1

sevenseacat
sevenseacat

Reputation: 25029

rails generate controller Admin
rails generate model Product

?

Upvotes: 1

Related Questions