Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto-generate routes for scaffolded controller in Rails 4?

I'm trying to get a quick-and-dirty Ajax UI going for an app that already has its data model well in hand - it's basically been managed via rails console so far. Anyway, I thought I would start by auto-generating the missing controller logic that you would get from a rails g scaffold, only instead with rails g scaffold_controller for an existing controller.

It created the controller, and the views, and the assets.. but it didn't touch the routes at all! It didn't even try, didn't say "warning: routes.rb has been modified, not changing" or anything like that, and there's no mention of routes at all in the help output of rails g scaffold_controller.

So how do I say "Just give me the normal routes you would have given me if I started from scratch, please!"?

like image 908
Mark Reed Avatar asked Nov 27 '25 04:11

Mark Reed


1 Answers

If I understand the question:

Please, open the config/routes.rb file, and inside the block (routes.draw) add the resources method with the table name (plural of model) as param. Like this:

MyApp::Application.routes.draw do
  resources :products
  ... # rest of code
end

That define the routes for RESTful actions over products. You can read more here

At the console you can run: rake routes to see the available routes at your app.

like image 105
Alejandro Babio Avatar answered Nov 28 '25 17:11

Alejandro Babio