結論 『リッチテキストが表示されない』
キータを参考に実装をしましたが、リッチテキストが表示されません。
contentの箇所が入力できない状態になっております。
https://gyazo.com/ae0de50e9eae21ecd14edd0a38897ccf
ご教授お願いいたします。
該当のソースコード
posts > _form.htnml.erb <%= form_with(model: post, local: true) do |form| %> <% if post.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(post.errors.count, "error") %> prohibited this post from being saved:</h2> <ul> <% post.errors.full_messages.each do |message| %> <li><%= message %></li> <% end %> </ul> </div> <% end %> <div class="field"> <%= form.label :title %> <%= form.text_field :title %> </div> <div class="field"> <%= form.label :content %> <%= form.rich_text_area :content %> </div> <div class="actions"> <%= form.submit %> </div> <% end %>
posts_controller class PostsController < ApplicationController before_action :set_post, only: [:show, :edit, :update, :destroy] before_action :move_to_index, except: [:index, :show] # GET /posts # GET /posts.json def index @posts = Post.all end # GET /posts/1 # GET /posts/1.json def show end # GET /posts/new def new @post = Post.new end # GET /posts/1/edit def edit end # POST /posts # POST /posts.json def create @post = Post.new(post_params) respond_to do |format| if @post.save format.html { redirect_to @post, notice: 'Post was successfully created.' } format.json { render :show, status: :created, location: @post } else format.html { render :new } format.json { render json: @post.errors, status: :unprocessable_entity } end end end # PATCH/PUT /posts/1 # PATCH/PUT /posts/1.json def update respond_to do |format| if @post.update(post_params) format.html { redirect_to @post, notice: 'Post was successfully updated.' } format.json { render :show, status: :ok, location: @post } else format.html { render :edit } format.json { render json: @post.errors, status: :unprocessable_entity } end end end # DELETE /posts/1 # DELETE /posts/1.json def destroy @post.destroy respond_to do |format| format.html { redirect_to posts_url, notice: 'Post was successfully destroyed.' } format.json { head :no_content } end end private # Use callbacks to share common setup or constraints between actions. def set_post @post = Post.find(params[:id]) end # Only allow a list of trusted parameters through. def post_params params.require(:post).permit(:title, :content) end def move_to_index unless user_signed_in? redirect_to action: :index end end end
posts_model class Post < ApplicationRecord has_rich_text :content end
試したこと
参考サイト:
https://qiita.com/tomokiyao/items/3c22ca9cb916d5c99ca4
https://qiita.com/774ihara/items/3523c109f4e874c31cc4
あなたの回答
tips
プレビュー