how to handle ActiveRecord::RecordNotFound in rails controller?

前端 未结 3 1499
闹比i
闹比i 2021-02-04 04:37

I have an app with user and events. Each user has several events. When a user wants to see a specific event he will get to this action:

def show
  begin
    @use         


        
3条回答
  •  情话喂你
    2021-02-04 04:52

    Put return after redirect

    begin
     @userEvents = current_user.event
     @event = @userEvents.find(params[:id])
    rescue ActiveRecord::RecordNotFound  
     redirect_to :controller => "main", :action => "index"
     return
    end
    

提交回复
热议问题