mardi 26 décembre 2017

Why is wrong redirecting?

Have model with tasks they are done and todo. In view have link and when click the link it must change task from todo to done. It's my routes

get 'tasks/:id', to: 'tasks#change_to_done', as: 'change_to_done'

my view

<% unless task.done %>
        <td><%= check_box_tag "cb_tasks[]", task.id %></td>
        <td><%= link_to task.title, task %></td>
        <td><%= link_to 'Edit', edit_task_path(task.id) %></td>
        <td><%= link_to 'Done', change_to_done_path(task.id) %></td>
        <td><%= link_to 'Destroy', task, method: :delete, data: {confirm: 'Are you sure?'} %></td>
      <% end %>

and my controller

  def change_to_done
    @task = Task.find(params[:id])
    @task.done = true
    @task.save
  end

when clicking the ling have redirecting to the show path

Started GET "/tasks/32" for 127.0.0.1 at 2017-12-26 11:59:06 +0200
Processing by TasksController#show as HTML
  Parameters: {"id"=>"32"}
  Task Load (0.1ms)  SELECT  "tasks".* FROM "tasks" WHERE "tasks"."id" = ? LIMIT ?  [["id", 32], ["LIMIT", 1]]
  Rendering tasks/show.html.erb within layouts/application
  Rendered tasks/show.html.erb within layouts/application (0.7ms)
Completed 200 OK in 57ms (Views: 55.0ms | ActiveRecord: 0.1ms)

What's wrong? I need only to change field state from false to true.




Aucun commentaire:

Enregistrer un commentaire