I am fairly new to Rails.
I want to track how often a post is read in order to rank them in order of popularity. Therefore, I will have a database column read_count
in the posts
table which increments by 1 each time #show is called.
However, if an admin is signed in and wants to preview the post via the #show method, I do not want the read_count
to increment.
I thought passing a custom param such as preview=true
in the params hash would be best. Then, #show would only increment read_count
if preview
evaluated to false or nil. But, how do I do that? What's the correct way to add preview=true
to the params hash?
Or would it be better to implement a #preview method on the controller?