[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

simple counting problem (inside rOrails controller

jotto

8/30/2006 2:07:00 AM

I want to count, perhaps with session variables, to ensure that the
user is not abusing AJAX features.

so on the particular page that has the ajax

unless session[:countcomment] !=nil
session[:countcomment] = 0.to_i
end

then, i check to see if the session[:countcomment] is greater than 1,
if it is, then no other ajax submissions are allowed, I tried to do
this with the following code:

if session[:countcomment].to_i > 1.to_i
if thiscomment.save
session[:countcomment] = session[:countcomment].to_i + 1.to_i
render some text
end
else
render_text "too many posts"
end

Except, this isn't working. Can variables be declared in Ruby? Is this
a poor approach to trying to limit AJAX activity?

1 Answer

Chris Hulan

8/30/2006 1:36:00 PM

0


jotto wrote:
.....
> unless session[:countcomment] !=nil
> session[:countcomment] = 0.to_i
> end

I would avoid the double negative:
session[:countcomment] = 0.to_i if session[:countcomment].nil?
....

> if session[:countcomment].to_i > 1.to_i
> if thiscomment.save
> session[:countcomment] = session[:countcomment].to_i + 1.to_i
> render some text
> end
> else
> render_text "too many posts"
> end

The logic here is saving the comment if the count is greater than 1?
The opposite of what you want.

Also, why all the to_i calls?

Cheers