忍者ブログ
[438]  [437]  [436]  [435]  [434]  [433]  [432]  [431]  [430]  [429]  [428
×

[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
カレンダー
03 2025/04 05
S M T W T F S
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
フリーエリア
最新CM
[03/10 DORA]
最新TB
プロフィール
HN:
dorabu
性別:
非公開
バーコード
ブログ内検索
P R
Copyright © ドラブーのアンドロイドとIoTなブログ All rights reserved. / Template by 四季. / Material by てんせん.

忍者ブログ [PR]