Controller that doesn't need a view (.rhtml file)

Hi,

I’m trying to add a small method to one of my controllers that simple
ticks up a column the db everytime a page is viewed. I plan on calling
the controller via a javascript include on the page. The method looks
something like this:

def update_product_view
product = Product.find_by_id(params[:id])
product.number_of_views += 1
product.save
end

Obviously, I don’t need any view here, as the intent is to just interact
with the DB. How do I tell rails not to bother looking for a view
template, and just stop after saving to the DB?

Thanks!

cman wrote:

Hi,

I’m trying to add a small method to one of my controllers that simple
ticks up a column the db everytime a page is viewed. I plan on calling
the controller via a javascript include on the page. The method looks
something like this:

def update_product_view
product = Product.find_by_id(params[:id])
product.number_of_views += 1
product.save
end

Obviously, I don’t need any view here, as the intent is to just interact
with the DB. How do I tell rails not to bother looking for a view
template, and just stop after saving to the DB?

Thanks!

def update_product_view
render :nothing => true
end

def update_product_view
render :nothing => true
end

Thank you for your quick response – that worked.

render :nothing => true

Got that near the end of the “render” documentation here: