Rails初学者です。Railsでタスク管理システムを作っています。
完了したタスクはbutton_tagでパラメータを送り完了済みにしたいのですが、現在
「param is missing or the value is empty」のエラーが出ている状況です。
現在の仕様としてはnew.html.erbでタスク内容とともに「未完了」のパラメータをhidden_fieldで送り、indexに表示しています。
想定している仕様としてはindexのページで「完了」のボタンを押下すると、未完了から完了に切り替わるシステムを実装したいです。
new
1<%= form_for(@task) do |form| %> 2 <%= form.text_field :title %> 3 <%= form.hidden_field :completed,:value => 0, id: 'task_completed' %> 4 <%= form.submit :class=>"btn-form" %>
index
1 <% @tasks.each do |task| %> 2 <%= form_with(model: task, local: true) do |form| %> 3 <%= task.title %> 4 <%= link_to image_tag('確認.png'), edit_task_path(task) %> 5 <%= link_to image_tag('削除.png'), task, method: :delete%> 6 <%= button_to "完了", completed_task_path(task) %> 7 <% end %> 8 <% end %>
ruby
1class TasksController < ApplicationController 2 ⋮ 3 ⋮ 4 def completed 5 @task = Task.new 6 @task = Task.where(:completed => 1) 7 render :action => 'index' 8 end 9 10 11 private 12 def set_task 13 @task = Task.find(params[:id]) 14 end 15 search_conditions = %i( 16 name 17 ) 18 def task_params 19 params.require(:task).permit(:title, :completed) 20 end 21end
routes
1Rails.application.routes.draw do 2 root 'tasks#index' 3 resources :tasks do 4 member do 5 get :completed 6 end 7 end 8end 9
以下が現在出ているエラー画面となっています。
ActionController::ParameterMissing in TasksController#update param is missing or the value is empty: task Extracted source (around line #82): 80 81 def task_params 82 params.require(:task).permit(:title, :limit, :point, :comment, :completed) 83 end 84 end Request Parameters: {"utf8"=>"✓", "_method"=>"patch", "authenticity_token"=>"J0Ys8GLxr0bg8+PTCaHP7BC07uNu5LWL7auEDQ8+i69NYncK1dlujVnqKJ074xoACoO3zyZgzv/0TolFK8+5fg==", "id"=>"15"}
かなり初歩的な内容ではあるかと思いますが、ご教示いただけますと幸いです。
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/29 05:16
2019/08/29 06:26
2019/08/29 07:37
2019/08/29 07:42
2019/08/29 08:41
2019/08/29 08:43
2019/08/29 09:02
2019/08/29 09:22