hi, could somebody tell me the difference between: if not params[:id] flash[:notice] = blabla'' redirect_to(:controller =>"calendar", :action => ''index'') end and: if params[:id] == nil flash[:notice] = blabla'' redirect_to(:controller =>"calendar", :action => ''index'') end the first one works, the second one doesn''t, but i don''t know why.... regards, remco -- Posted via http://www.ruby-forum.com/.
On 8/7/06, Remco Hh <remco@huijdts.nl> wrote:> > hi, could somebody tell me the difference between: > > if not params[:id] > flash[:notice] = blabla'' > redirect_to(:controller =>"calendar", :action => ''index'') > end > > and: > > if params[:id] == nil > flash[:notice] = blabla'' > redirect_to(:controller =>"calendar", :action => ''index'') > end > > > the first one works, the second one doesn''t, but i don''t know why.... > > regards, > > remco > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >I don''t have ruby here with me at the moment since I''m at work so I can''t check this :( But I think it could be that params[:id] is not defined. So saying not params[:id] would be true. but since it''s not defined then params[:id] cannot == nil To check that this is the case include something like put "Params is defined #{params[:id].defined?}" in your code and have a look. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060807/0f705fd6/attachment.html
On Monday, August 07, 2006, at 9:48 AM, Remco Hh wrote:>hi, could somebody tell me the difference between: > >if not params[:id] > flash[:notice] = blabla'' > redirect_to(:controller =>"calendar", :action => ''index'') >end > >and: > >if params[:id] == nil > flash[:notice] = blabla'' > redirect_to(:controller =>"calendar", :action => ''index'') >end > > >the first one works, the second one doesn''t, but i don''t know why.... > >regards, > >remco > >-- >Posted via http://www.ruby-forum.com/. >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/railsBoth of these should work provided that params does not contain an :id key. This is probably a better syntax though... unless params[:id] flash[:notice] = ''blabla'' redirect_to(:controller =>"calendar", :action => ''index'') end or if params[:id].nil? flash[:notice] = ''blabla'' redirect_to(:controller =>"calendar", :action => ''index'') end _Kevin www.sciwerks.com -- Posted with http://DevLists.com. Sign up and save your mailbox.
Kevin Olbrich wrote:> On Monday, August 07, 2006, at 9:48 AM, Remco Hh wrote: >> flash[:notice] = blabla'' >>-- >>Posted via http://www.ruby-forum.com/. >>_______________________________________________ >>Rails mailing list >>Rails@lists.rubyonrails.org >>http://lists.rubyonrails.org/mailman/listinfo/rails > > Both of these should work provided that params does not contain an :id > key. > > This is probably a better syntax though... > > unless params[:id] > flash[:notice] = ''blabla'' > redirect_to(:controller =>"calendar", :action => ''index'') > end > > or > > if params[:id].nil? > flash[:notice] = ''blabla'' > redirect_to(:controller =>"calendar", :action => ''index'') > end > > > _Kevin > www.sciwerks.comthanks both for your reply! kevin, you are right, this looks better and more ruby-like :) -- Posted via http://www.ruby-forum.com/.