title: how to handle ActiveRecord::RecordNotFound in rails controller?
body: <p>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:</p>
  
  <pre><code>def show
    begin
      @userEvents = current_user.event
      @event = @userEvents.find(params[:id])
    rescue ActiveRecord::RecordNotFound  
      redirect_to :controller =&gt; "main", :action =&gt; "index"
    end
  
    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @event }
    end
  end
  </code></pre>
  
  <p>If the event is not found for the user it means he played with the URL and the event he is trying to get does not belong to him. I want to either redirect him to the main page or just display the page with an error that the event is not found. If I try to run the code above this error fires:</p>
  
  <pre><code>AbstractController::DoubleRenderError in EventsController#show 
  </code></pre>
  
  <p>What's the best way to fix this?</p>