This project is archived and is in readonly mode.

#3091 ✓invalid
Claudio Poli

respond_with not working on namespaced/singleton resource

Reported by Claudio Poli | August 24th, 2009 @ 05:00 PM


class Dashboard::Superenalotto::CombinationsController < DashboardController

  respond_to :html

  def create
    @superenalotto_combination =[:superenalotto_combination])
    flash[:notice] = 'Combination created.' if
    respond_with([:dashboard, @superenalotto_combination])

:dashboard is a namespaced route.

as per source documentation in actionpack/lib/action_controller/metal/responder.rb from my understanding this should be valid code; this will never render the :new action template if validations fails because the resource is an array.

in fact in the same file we have the method has_errors? which is used to check if a record has passed validation or not, but using the respond_with explained above in create action the resource is an array, therefore will not respond_to?(:errors), let out .errors method.

the resource that appears in has_errors? method in this case is:

[:dashboard, #<SuperenalottoCombination id: nil, user_id: 2, ...]

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket