projecthydra-labs/orcid — pull request #23 by jeremyf (2014-05-15 19:57:32+00:00)
Title: Fixing singular Rails resource behavior

Since we have a singular resource for ProfileRequest, the
`Controller#respond_with` was treating the profile_request parameter
as the :format option (i.e. format = 'xml').

The solution was to tease apart the automagic behavior of the
`#respond_with` method into its two response options for
transformative actions - either render the page with errors or
redirect due to success.

I believe this is related to https://github.com/rails/rails/issues/1769,
which is called out in http://guides.rubyonrails.org/routing.html#singular-resources

Below is a more detailed breakdown of what I am refering to:

The ProfileRequest is a singular resource.

```ruby
Orcid::Engine.routes.draw do
scope module: 'orcid' do
resource :profile_request, only: [:show, :new, :create]
resources :profile_connections, only: [:new, :create, :index]
end
end
```

As a singluar resource the following routes are available.

```console
$ rake app:routes
Routes for Orcid::Engine:
profile_request POST /profile_request(.:format) orcid/profile_requests#create
new_profile_request GET /profile_request/new(.:format) orcid/profile_requests#new
GET /profile_request(.:format) orcid/profile_requests#show
```

If we had a plural resource for ProfileRequest
```ruby
Orcid::Engine.routes.draw do
scope module: 'orcid' do
resources :profile_request, only: [:show, :new, :create]
resources :profile_connections, only: [:new, :create, :index]
end
end
```

Then the routes would be:
```console
$ rake app:routes
profile_request_index POST /profile_request(.:format) orcid/profile_request#create
new_profile_request GET /profile_request/new(.:format) orcid/profile_request#new
profile_request GET /profile_request/:id(.:format) orcid/profile_request#show
```