Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy do I need to work harder to make my Rails application fit into a RESTful architecture?
    primarykey
    data
    text
    <p>I started a Rails project recently and decided to use RESTful controllers. I created controllers for my key entities (such as Country) and added <code>index</code>, <code>new</code>, <code>edit</code>, <code>create</code>, <code>show</code>, <code>update</code> and <code>delete</code>. I added my <code>map.resources :country</code> to my routes file and life was good.</p> <p>After development progressed a little, I started to encounter problems. I sometimes needed extra actions in my controller. First there was the <code>search</code> action that returned the options for my fancy autocompleting search box. Then came the need to display the countries in two different ways in different places in the application (the data displayed was different too, so it wasn't just two views) - I added the <code>index_full</code> action. Then I wanted to show a country by name in the URL, not by id so I added the <code>show_by_name</code> action.</p> <p>What do you do when you need actions beyond the standard <code>index</code>, <code>new</code>, <code>edit</code>, <code>create</code>, <code>show</code>, <code>update</code>, <code>delete</code> in a RESTful controller in Rails? Do I need to add (and maintain) manual routes in the routes.rb file (which is a pain), do they go in a different controller, do I become unRESTful or am I missing something fundamental?</p> <p>I guess I am asking, do I need to work harder and add actions into my routes.rb file for the privilege of being RESTful? If I wasn't using <code>map.resources</code> to add the REST goodies, the standard <code>:controller/:action, :controller/:action/:id</code> routes would handle pretty much everything automatically.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload