simple counting problem (inside rOrails controller)

J

jotto

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?
 
C

ChrisH

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top