remcoh
August 7, 2006, 9:48am
1
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
remcoh
August 7, 2006, 1:27pm
2
On 8/7/06, Remco Hh [email protected] wrote:
if params[:id] == nil
–
Posted via http://www.ruby-forum.com/ .
Rails mailing list
[email protected]
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.
remcoh
August 7, 2006, 1:42pm
3
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
[email protected]
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.com
remcoh
August 7, 2006, 2:36pm
4
Kevin O. 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
[email protected]
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.com
thanks both for your reply!
kevin, you are right, this looks better and more ruby-like