Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

respond_with not working on namespaced/singleton resource

#3091

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, ...]

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

State: invalid
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Claudio Poli
    Claudio Poli

    mm, sorry about the improper ticket title, feel free to modify.

    August 24th, 2009 @ 05:02 PM

  2. Claudio Poli
    Claudio Poli

    whops, just removed the array syntax and got it working. my bad, sorry for the noise.

    August 24th, 2009 @ 05:07 PM

  3. José Valim
    José Valim
    • State changed from new to invalid

    August 30th, 2009 @ 09:40 AM