Tuesday, April 10, 2012

Why does this rescue syntax work?

Ok so i have this method of an application I am working with and it works in production ...My question why does this work. Is this new rails syntax



def edit
load_elements(current_user) unless current_user.role?(:admin)

respond_to do |format|
format.json { render :json => @user }
format.xml { render :xml => @user }
format.html
end

rescue ActiveRecord::RecordNotFound
respond_to_not_found(:json, :xml, :html)
end




1 comment:

  1. rescues do not need to be tied to an explicit begin when they're in a method, that's just the way the syntax is defined. For examples, see #19 here and this SO question, as well as the dupe above.

    ReplyDelete