D
D
destroy_sys2015-01-23 16:37:02
Ruby on Rails
destroy_sys, 2015-01-23 16:37:02

[param is missing or the value is empty: task] How to solve?

I am making a ToDo application (everything I am doing now is purely for practicing skills, understanding where the gaps are). I ran into a problem, I don’t know how to implement the following:
When you click on the checkmark, the task parameter :complete_task changes from false to true.
451a9e43fab34527ad982d4657fdde64.png
I decided that I have a problem with the design of routes. I tried to implement it myself as follows: I
created a method in the task controller

def complete_todo
  @task = Task.find(params[:id])
  @task.complete_task = true
  if @task.update(task_params)
    redirect_to root_path
  end
end

I wrote in the itinerary:
post 'tasks/complete_todo/:id',    to: 'tasks#complete_todo', as: 'finished_task'

How to solve this problem - I do not know, I've been suffering for 4 hours already. When trying to mark a task as completed, an error occurs:
param is missing or the value is empty: task

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jeiwan, 2015-01-23
@destroy_sys

param is missing or the value is empty: task

The action is waiting for the 'task' parameter to come, but it doesn't. Why? Because you don't send it. That is, you have the wrong form. Or rather, you have no form at all.
Here is the proof that 'task' is not passed.
Why is this update needed? What is the logic? Why update the whole task?
In general, it’s not comme il faut to do this in controllers. The model must work with the database. It's better to make the method 'complete!' in the model and in the controller it's easy to call @task.complete!
Well, the route is not entirely correct.
post 'tasks/:id/complete', to: 'tasks#complete', as: 'complete_task'
- that would have been better. Rename the action accordingly.
Or if making a resource:
resources :tasks do
  post :complete, on: :member
end

How to fix, I think, now guess :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question