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

given

class Dashboard::Superenalotto::CombinationsController < DashboardController

  respond_to :html

  def create
    @superenalotto_combination = current_user.superenalotto_combinations.build(params[:superenalotto_combination])
    flash[:notice] = 'Combination created.' if @superenalotto_combination.save
    respond_with([:dashboard, @superenalotto_combination])
  end

: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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages