Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

routes in rails - removing actions when setting up a resource

I've setup a simple app and added a scaffold to do some of the work for me (I'm a noob).

  resources :cars 

How do I remove certain actions from the routes? And remove the corresponding urls?

For example I want to keep the 'show' and 'edit' actions & urls.

But I don't want there to be a 'new' 'index' or 'delete'

I understand this is probably a really simple question, but I've not been able to find an answer.

like image 385
Finnnn Avatar asked Nov 24 '11 14:11

Finnnn


People also ask

How does routing work in Rails?

Rails routing is a two-way piece of machinery – rather as if you could turn trees into paper, and then turn paper back into trees. Specifically, it both connects incoming HTTP requests to the code in your application's controllers, and helps you generate URLs without having to hard-code them as strings.

How many types of routes are there in Rails?

Rails RESTful Design which creates seven routes all mapping to the user controller. Rails also allows you to define multiple resources in one line.

What are the 7 CRUD routes generated by the resources Method resources songs in Rails?

In Rails, there are seven standard CRUD actions: index, show, new, create, edit, update, and destroy, which relate to specific HTTP verbs and are usually implemented using specific ActiveRecord methods.

What are Rails resource routes?

Any object that you want users to be able to access via URI and perform CRUD (or some subset thereof) operations on can be thought of as a resource. In the Rails sense, it is generally a database table which is represented by a model, and acted on through a controller.


1 Answers

resources :cars, :except => [:new, :index, :delete] 

or

resources :cars, :only => [:show, :edit] 

Also take a look at Rails Guides

like image 54
Mikhail Nikalyukin Avatar answered Sep 26 '22 01:09

Mikhail Nikalyukin