diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e29ed47..19ae2ed 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,4 +3,11 @@ class ApplicationController < ActionController::Base allow_browser versions: :modern include Pagy::Backend + + private + + def back_params + request.query_parameters.slice("q", "sort", "page") + end + helper_method :back_params end diff --git a/app/controllers/publications_controller.rb b/app/controllers/publications_controller.rb index 5412289..a48c38a 100644 --- a/app/controllers/publications_controller.rb +++ b/app/controllers/publications_controller.rb @@ -38,7 +38,7 @@ def create @publication = current_user.publications.build(publication_params) if @publication.save(context: :ui) NotificationMailer.new_publication_notification(@publication).deliver_now - redirect_to @publication, notice: "Publication was successfully created." + redirect_to publication_path(@publication, back_params), notice: "Publication was successfully created." else render :new, status: :unprocessable_entity end @@ -56,7 +56,7 @@ def update NotificationMailer.publication_update_notification(@publication, current_user, payload).deliver_now @publication._notification_changes = nil end - redirect_to @publication, notice: "Publication was successfully updated." + redirect_to publication_path(@publication, back_params), notice: "Publication was successfully updated." else render :edit, status: :unprocessable_entity end @@ -64,7 +64,7 @@ def update def destroy @publication.destroy - redirect_to publications_path, notice: "Publication was successfully deleted." + redirect_to publications_path(back_params), notice: "Publication was successfully deleted." end private diff --git a/app/views/publications/_search_form.html.erb b/app/views/publications/_search_form.html.erb index d1a6765..b2b23a9 100644 --- a/app/views/publications/_search_form.html.erb +++ b/app/views/publications/_search_form.html.erb @@ -138,7 +138,11 @@ <% end %> -
+
+ <%= link_to "Reset filters", + publications_path(back_params.except("q", "page")), + class: "btn btn-secondary" %> + <%= f.submit "Search", class: "btn btn-primary" %>
<% end %> diff --git a/app/views/publications/edit.html.erb b/app/views/publications/edit.html.erb index 001b8cd..bc67257 100644 --- a/app/views/publications/edit.html.erb +++ b/app/views/publications/edit.html.erb @@ -1,10 +1,13 @@
- <%= link_to publication_path(@publication), class: "text-decoration-none text-muted small d-inline-flex align-items-center gap-1 fs-6" do %> + <%= link_to publication_path(@publication, back_params), + class: "text-decoration-none text-muted small d-inline-flex align-items-center gap-1 fs-6" do %> Back <% end %>
-<%= simple_form_for @publication, html: { class: 'needs-validation' } do |form| %> +<%= simple_form_for @publication, + url: publication_path(@publication, back_params), + html: { class: 'needs-validation' } do |form| %>
diff --git a/app/views/publications/index.html.erb b/app/views/publications/index.html.erb index 8a03131..16428df 100644 --- a/app/views/publications/index.html.erb +++ b/app/views/publications/index.html.erb @@ -26,7 +26,7 @@ data: { controller: "sort", action: "change->sort#submit" } %>
- <%= search_form_for @q, url: publications_path, method: :get do |f| %> + <%= search_form_for @q, url: publications_path(back_params.except("q", "page")), method: :get do |f| %> <%= f.search_field :title_cont, class: "form-control search-field", placeholder: "Search publications by title" %> <% end %>
@@ -64,7 +64,7 @@
- <%= link_to publication.title, publication_path(publication), class: "text-decoration-none" %> + <%= link_to publication.title, publication_path(publication, back_params), class: "text-decoration-none" %>
diff --git a/app/views/publications/new.html.erb b/app/views/publications/new.html.erb index d66541c..a27ed35 100644 --- a/app/views/publications/new.html.erb +++ b/app/views/publications/new.html.erb @@ -1,10 +1,13 @@
- <%= link_to publications_path, class: "text-decoration-none text-muted small d-inline-flex align-items-center gap-1 fs-6" do %> + <%= link_to publications_path(back_params), + class: "text-decoration-none text-muted small d-inline-flex align-items-center gap-1 fs-6" do %> Back <% end %>
-<%= simple_form_for @publication, html: { class: 'needs-validation' } do |form| %> +<%= simple_form_for @publication, + url: publications_path(back_params), + html: { class: 'needs-validation' } do |form| %>
diff --git a/app/views/publications/show.html.erb b/app/views/publications/show.html.erb index 456b023..cf16e3d 100644 --- a/app/views/publications/show.html.erb +++ b/app/views/publications/show.html.erb @@ -1,5 +1,6 @@
- <%= link_to publications_path, class: "text-decoration-none text-muted small d-inline-flex align-items-center gap-1 fs-6" do %> + <%= link_to publications_path(back_params), + class: "text-decoration-none text-muted small d-inline-flex align-items-center gap-1 fs-6" do %> Back <% end %>
@@ -13,9 +14,9 @@
- <%= link_to "Edit publication", edit_publication_path(@publication), class: 'btn btn-primary' %> + <%= link_to "Edit publication", edit_publication_path(@publication, back_params), class: 'btn btn-primary' %> - <%= button_to "Delete", publication_path(@publication), + <%= button_to "Delete", publication_path(@publication, back_params), method: :delete, data: { confirm: "Are you sure?" }, form: { class: "d-grid" }, diff --git a/app/views/research_groups/index.html.erb b/app/views/research_groups/index.html.erb index dfbec26..df7ff6d 100644 --- a/app/views/research_groups/index.html.erb +++ b/app/views/research_groups/index.html.erb @@ -1,5 +1,6 @@
- <%= link_to publications_path, class: "text-decoration-none text-muted small d-inline-flex align-items-center gap-1 fs-6" do %> + <%= link_to publications_path(back_params), + class: "text-decoration-none text-muted small d-inline-flex align-items-center gap-1 fs-6" do %> Back <% end %>