I have this index
action in my Rails app:
class ProjectsController < ApplicationController
def index
if %w[year quarter month].include?(params[:sort_by])
order = params[:sort_by]
else
order = "year"
end
......
end
end
Now if a user enters /projects?sort_by=foo
it would be nice to have that GET parameter removed from the URL string immediately and redirect to /projects
.
What's the best way to achieve that?
If there's anything else I can do to make my code safer, please let me know.
Thanks for any help.
您可以尝试通过在视图文件中添加JavaScript replaceState()函数从浏览器的URL中删除不需要的GET参数。
history.replaceState({}, '', '/projects');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.