evaluating rubycode after redirect

Hi,

there is somthing, that I do not understand.

class MyController < ApplicationController

  def index     ...   end

  def my_def     redirect_to :action=> "index" unless params[:id]

    my_model = MyModel.find(params[:id])     ...   end end

when I try to call "my_controller/my_def" without an id in y browser, then the find-statement will is evaluated :frowning: why?!?

thanks Guido

when I try to call "my_controller/my_def" without an id in y browser, then the find-statement will is evaluated :frowning: why?!?

thanks Guido

because redirect_to is not a return.. it's a method call.. use the following form:

def my_def   if params[:id]     my_model = MyModel.find params[:id]   else     redirect_to :action => "index"   end end