Counting the page views

Is this model just for counting?

You need to find the current record, then save your changes to get the database to update.

You should perform this in a transaction to keep one view from stomping on another. See ActiveRecord::Base::transaction class method.

Michael

There's a cleaner way: ActiveRecord::Base#increment! increases the passed attribute by 1 and saves the record.

def showadvert   @advert = Advert.find(params[:id])   @advert.increase!("views") end

then you can just show it in your views as you suggested:

<%= @advert.views %>