link_to redirecting instead of opening modal

58 Views Asked by At

I have 2 edit buttons in 2 different pages. One is working perfectly opening a modal to edit, the other one is redirecting to a page that doesn't exist. How can I fix that? I am using ruby on rails 5.2.6 and bootstrap 5.2.

Button that is working opening a modal:

<%= link_to icon('fas', 'pen'), edit_task_path(task, redirect_to: tasks_url(view: params[:view])), title: 'Editar', remote: true, class: "px-1" %>

I tryind to add a byebug before this button and got this results:

(byebug) tasks_url(view: params[:view]) "http://localhost:3000/tasks?view=table" (byebug) params <ActionController::Parameters {"group_by"=>"task_category_html", "view"=>"table", "controller"=>"tasks", "action"=>"index", "default_date"=>Thu, 07 Dec 2023} permitted: false>

Button that is redirecting to a different page:

<%= link_to edit_task_path(task, redirect_to: tasks_url(view: params[:view])), remote: true, class: 'btn btn-outline-primary' %>
        <span class="fas fa-pen" aria-hidden="true"></span> Editar
<% end %>

I tried to add a byebug before the button and got this results:

(byebug) tasks_url(view: params[:view])
"http://localhost:3000/tasks?view=table"
(byebug) params
<ActionController::Parameters {"group_by"=>"task_category_html", "view"=>"table", "controller"=>"tasks", "action"=>"index", "default_date"=>Thu, 07 Dec 2023} permitted: false>
2

There are 2 best solutions below

1
Bhupendra Singh On

You have missed the do keyword in the link_to statement, Please try this

<%= link_to edit_task_path(task, redirect_to: tasks_url(view: params[:view])), remote: true, class: 'btn btn-outline-primary' do %>

0
Sriram On

I think the problem is :redirect_to on your link_to method. Try this <%= link_to icon('fas', 'pen'), edit_task_path(task, tasks_url(view: params[:view])), title: 'Editar', remote: true, class: "px-1" %>