

### 前提・実現したいこと

投稿カラムの title, body の編集、update ができません。  
エラーがなくどこが悪いのか特定できず詰まっています。  
コントローラーのupdateメソッドが毎回falseでrender
:editを実行しているためだと考えましたがupdateがfalseになってしまう原因がわかりません。

### 発生している問題・エラーメッセージ

  * updateできない
  * book_cotrollerのupdateアクション内のupdateメソッドがfalse

  * エラーメッセージなし

### 該当のソースコード

下記の他に必要なものがあればコメントもらい次第追加します。よろしくお願いします。

* * *

**books_controller.rb**

[code]

    class BooksController < ApplicationController
      before_action :set_book, only: [:show, :edit, :update, :destroy]
    
      # GET /books
      # GET /books.json
      def index
        @book = Book.new
        @books = Book.all
      end
    
      # GET /books/1
      # GET /books/1.json
      def show
      end
    
      # GET /books/1/edit
      def edit
      end
    
      # POST /books
      # POST /books.json
      def create
        @book = Book.new(book_params)
        if @book.save
          redirect_to @book, notice: 'Book was successfully created.'
        else
          render :index
        end
      end
    
      # PATCH/PUT /books/1
      # PATCH/PUT /books/1.json
      def update
        if @book.update(book_params)
          redirect_to books_path, notice: 'Book was successfully updated.'
        else
          raise @book.error
          render :index , notice: 'update was failed'
        end
      end
    
      # DELETE /books/1
      # DELETE /books/1.json
      def destroy
        @book.destroy
        redirect_to books_url, notice: 'Book was successfully destroyed.'
      end
    
      private
        # Use callbacks to share common setup or constraints between actions.
        def set_book
          @book = Book.find(params[:id])
        end
    
        # Never trust parameters from the scary internet, only allow the white list through.
        def book_params
          params.require(:book).permit(:title, :body)
        end
    end
    
[/code]

**_form.html.erb**

[code]

    <%= form_for(book) do |f| %>
      <% if book.errors.any? %>
        <div id="error_explanation">
          <h2><%= pluralize(book.errors.count, "error") %> prohibited this book from being saved:</h2>
    
          <ul>
          <% book.errors.full_messages.each do |message| %>
            <li><%= message %></li>
          <% end %>
          </ul>
        </div>
      <% end %>
    
      <div class="field">
        <%= f.label :title %>
        <%= f.text_field :title, class: "book_title" %>
      </div>
    
      <div class="field">
        <%= f.label :body %>
        <%= f.text_area :body, class: "book_body" %>
      </div>
    
      <div class="actions">
        <%= f.submit %>
      </div>
    <% end %>
    
[/code]

**edit.html.erb**

[code]

    <h1>Editing Book</h1>
    <%= @book.body %>
    <form>
      <%= render 'form',{ book: @book }%>
    </form>
    
    <%= link_to 'Show', @book, class: "show_#{@book.id}" %> |
    <%= link_to 'Back', books_path, class: "back" %>
    
[/code]

**routes.rb**

[code]

    Rails.application.routes.draw do
      resources :books
      # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
    end
    
[/code]

### 補足情報（FW/ツールのバージョンなど）

Rails 5.2.4.3


CC BY-SA 4.0
2020-06-03T09:16:09.887
67255
2020-06-03T11:34:54.790
2020-06-03T11:34:54.790
3060
question
ruby-on-rails
rails アプリで投稿カラムの編集や更新ができない