ruby on rails - How to return a value without `return` -


how can return without return devise's authenticate! method does?

class groupscontroller < applicationcontroller   def create     authenticate! # after here, code below not excuted.     @group = group.create(group_params)     redirect_to groups_path   end end 

i wondering how this.

the devise authenticate! doesn't return on failure, throw exceptions if user isn't authenticated. exception propagated through call chain, until hits matched rescue statement. rails framework smart enough rescue kind of exception , convert specific exceptions corresponding http status code, example, activerecord::recordnotfound converted 404.

this common programming tricks return deep call hierarchy.

def   raise "ha" end def b   puts "calling a"     not executed end def c   b rescue nil end  c #=> calling 

and ruby provides catch/throw serve kind of deeper jump.

catch(:ret)   (1..5).each |i|     (1..5).each |j|       puts * j       throw :ret if * j > 3     end   end end 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -