问题
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
回答1:
if params[:page].blank?
redirect_to :page => 1
end
回答2:
Simply check,
if request.query_string.present?
# Do your stuff here.
end
Thats it ! Cheers!!!!
来源:https://stackoverflow.com/questions/6888946/how-can-i-check-if-there-is-a-query-string-from-a-ruby-on-rails-controller