This errors as I can''t jump out of the action with render multiple times. "Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return"." Fair enuf'' - but how do I do this? def update params[:advert][:resort_ids] ||= [] # Fix from one of Ryan''s railscasts for checkbox updates if current_user.admin @advert.cleared_for_release params[:advert][:cleared_for_release] # protected with attr_protected in model @advert.front_page = params[:advert][:front_page] # protected with attr_protected in model @advert.save end puts "**** SUBMITTED resort count :" + params[:advert][:resort_ids].length.to_s puts "**** ALLOWED resort count :" + current_user.max_allowed_resorts_per_advert.to_s allowed_resorts = current_user.max_allowed_resorts_per_advert requested_resorts = params[:advert][:resort_ids].length if requested_resorts > allowed_resorts flash[:notice] = "Sorry you''re only allowed to list against #{allowed_resorts} resorts." render :action => ''edit'' # Update probably failed validation, re edit end @advert = Advert.find(params[:id]) if @advert.update_attributes(params[:advert]) flash[:notice] = "Updated. Done." redirect_to @advert else render :action => ''edit'' # Update probably failed validation, re edit end end -- Posted via http://www.ruby-forum.com/.
2009/8/31 bingo bob <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > This errors as I can''t jump out of the action with render multiple > times. > > "Render and/or redirect were called multiple times in this action. > Please note that you may only call render OR redirect, and at most once > per action. Also note that neither redirect nor render terminate > execution of the action, so if you want to exit an action after > redirecting, you need to do something like "redirect_to(...) and > return"." > > Fair enuf'' - but how do I do this? > > > > > > def update > params[:advert][:resort_ids] ||= [] # Fix from one of Ryan''s > railscasts for checkbox updates > > if current_user.admin > -LNb1nb+/th8Iuath06xHZw@public.gmane.org_for_release > params[:advert][:cleared_for_release] # protected with > attr_protected in model > -iJmZj6UzwtmNwaa6RkDhIg@public.gmane.org_page = params[:advert][:front_page] > # protected with attr_protected in model > -Wi2ZNfifYtHfhZSSa7DgLw@public.gmane.org > end > > puts "**** SUBMITTED resort count :" + > params[:advert][:resort_ids].length.to_s > puts "**** ALLOWED resort count :" + > current_user.max_allowed_resorts_per_advert.to_s > > allowed_resorts = current_user.max_allowed_resorts_per_advert > requested_resorts = params[:advert][:resort_ids].length > > if requested_resorts > allowed_resorts > flash[:notice] = "Sorry you''re only allowed to list against > #{allowed_resorts} resorts." > render :action => ''edit'' # Update probably failed > validation, re editDo what the message suggests and put a return here so that it does not go on and do the next bit as well. Or possibly better use an else here and drop to the bottom. Or even better reorganise the logic so that there is only one call to render :action => ''edit''. Colin> end > > > @advert = Advert.find(params[:id]) > if @advert.update_attributes(params[:advert]) > flash[:notice] = "Updated. Done." > redirect_to @advert > else > render :action => ''edit'' # Update probably failed > validation, re edit > end > end > -- > Posted via http://www.ruby-forum.com/. > > > >