×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
controllerの編集
class TasksController < ApplicationController
def index
@tasks = Task.all.order(created_at: 'desc')
end
def show
@task = Task.find(params[:id])
end
def new
@task = Task.new
end
def edit
@task = Task.find(params[:id])
end
def create
#task_params
task=Task.new(params.require(:task).permit(:name, :description))
#task = Task.new
# task.attributes = {name: params[:task][:name], description: params[:task][:description]}
#@task= Task.new(task_params )
#@task = Task.new(task_params)
#if @task.save
if task.save!
#redirect
flash[:notice] ="タスク 「#{task.name}」を登録しました"
redirect_to tasks_path
else
#render plain:@post.errors.inspect
render :new
end
end
def update
@task = Task.find(params[:id])
if @task.update(params.require(:task).permit(:name, :description))
# @task = Task.find(params[:id])
# if @task.update(task_params)
flash[:notice] ="タスク 「#{@task.name}」を更新しました"
redirect_to tasks_path
else
render 'edit'
end
end
def destroy
task = Task.find(params[:id])
task.destroy
flash[:notice] ="タスク 「#{task.name}」を削除しました"
redirect_to tasks_path
end
private
def task_params
params.require(:task).permit(:name,:description,:dat1)
end
end
class TasksController < ApplicationController
def index
@tasks = Task.all.order(created_at: 'desc')
end
def show
@task = Task.find(params[:id])
end
def new
@task = Task.new
end
def edit
@task = Task.find(params[:id])
end
def create
task_params
task = Task.new
task.attributes = {name: params[:task][:name], description: params[:task][:description]}
#@task= Task.new(task_params )
#@task = Task.new(task_params)
#if @task.save
#if @task.save
if task.save!
#redirect
flash[:notice] ="タスク 「#{task.name}」を登録しました"
redirect_to tasks_path
else
#render plain:@post.errors.inspect
render :new
end
end
def update
@task = Task.find(params[:id])
if @task.update(params.require(:task).permit(:name, :description))
# @task = Task.find(params[:id])
# if @task.update(task_params)
flash[:notice] ="タスク 「#{@task.name}」を更新しました"
redirect_to tasks_path
else
render 'edit'
end
end
def destroy
task = Task.find(params[:id])
task.destroy
flash[:notice] ="タスク 「#{task.name}」を削除しました"
redirect_to tasks_path
end
private
def task_params
params.require(:task).permit(:name,:description,:dat1)
end
end
PR