前提・実現したいこと
ruby on rails5でタスク管理アプリを作っています。
タスクを新規登録する際以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
NoMethodError in Tasks#show
show.html.slim where line #9 raised:
#####tasks/show.html.slim
h1 ユーザーの詳細 .nav.justify-content-end = link_to '一覧',admin_users_path,class: 'nav-link' table.table.table-hover tbody tr th= User.human_attribute_name(:id) td= @user.id tr th= User.human_attribute_name(:name) td= @user.name tr th= User.human_attribute_name(:email) td= @user.email tr th= User.human_attribute_name(:admin) td= @user.admin? ? 'あり':'なし' tr th= User.human_attribute_name(:created_at) td= @user.created_at tr th= User.human_attribute_name(:updated_at) td= @user.updated_at tr th= User.human_attribute_name(:description) td= auto_link(simple_format(h(@task.description), {}, sanitize: false, wrapper_tag: "div")) =link_to '編集',edit_admin_user_path,class:'btn btn-primary mr-3' =link_to '削除',[:admin,@user],method: :delete, data: { confirm: "ユーザー『#{@user.name}』を削除します。よろしいですか?" }, class: 'btn btn-danger'
#####tasks_controller.rb
class TasksController < ApplicationController before_action :set_task, only: [:show, :edit, :update, :destroy] def index @tasks = current_user.tasks.order(created_at: :desc) end def show end def new @task = Task.new end def edit end def update task.update!(task_params) redirect_to tasks_url, notice:"タスク『#{task.name}』を更新しました。" end def destroy task.destroy redirect_to tasks_url, notice:"タスク『#{task.name}」を削除しました。" end def create @task = current_user.tasks.new(task_params) if @task.save redirect_to @task, notice: "タスク『#{@task.name}』を登録しました。" else render :new end end private def task_params params.require(:task).permit(:name, :description) end def set_task @task = current_user.tasks.find(params[:id]) end end
試したこと
9行目と言われているため、idの新規登録?が出来ていないのかなと思うのですが
どこを修正すれば良いのかがわかりません。
エラーが出た後にurlの数字の部分を消してアクセスするとタスクは無事登録されています。
情報が足りないなどありましたら仰ってください。
どなたかお力貸してください!
よろしくお願い致します。
補足情報(FW/ツールのバージョンなど)
ruby on rails5
回答1件
あなたの回答
tips
プレビュー