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 :-( why?!?
thanks Guido
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
> > when I try to call "my_controller/my_def" without an id in y browser, > then the find-statement will is evaluated :-( why?!? > > thanks Guidobecause 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---