I'm using pagination on our Ruby on Rails app and the pages are defined in the request with a query string parameter like
http://ourdomain.com/?page=2
I use this on our front page where there's no page number explicitly defined.
I'd like to do a check to see if there is a query string, and if not then display the correct page=1, by redirecting to that page I presume
Does anyone know how I can do this?
Thanks ahead for any help
However, regardless of whether the query string is used or not, the whole URL including it is stored in the server log files. These facts allow query strings to be used to track users in a manner similar to that provided by HTTP cookies.
When writing controllers in Ruby on rails, using before_action (used to be called before_filter in earlier versions) is your bread-and-butter for structuring your business logic in a useful way. It's what you want to use to "prepare" the data necessary before the action executes.
Simply check,
if request.query_string.present?
# Do your stuff here.
end
Thats it ! Cheers!!!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With