Simple counting problem (inside rOrails controller)

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?

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