2009/8/31 bingo bob <[email protected]>: > > 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 > �[email protected]_for_release = > params[:advert][:cleared_for_release] # protected with > attr_protected in model > �[email protected]_page = params[:advert][:front_page] > # protected with attr_protected in model > �[email protected] > 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
Do 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/. > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

