rich_text_area を表示させたい
ActionTextを記述、インストールし
rich_text_areaのコードを記述しましたが、
タイトル部分だけ記入欄が表示され、
contentの部分が表示されません。
https://gyazo.com/ae1ee59958ae4f6412a93aa799161dd5
bootstrapでscssを指定しているからでしょうか
ご教授お願いいたします。
該当のソースコード
fomeHTMLerb
1<%= form_with(model: post, local: true) do |form| %> 2 <% if post.errors.any? %> 3 <div id="error_explanation"> 4 <h2><%= pluralize(post.errors.count, "error") %> prohibited this post from being saved:</h2> 5 6 <ul> 7 <% post.errors.full_messages.each do |message| %> 8 <li><%= message %></li> 9 <% end %> 10 </ul> 11 </div> 12 <% end %> 13 14 <div class="field"> 15 <%= form.label :title %> 16 <%= form.text_field :title %> 17 </div> 18 19 <div class="field"> 20 <%= form.label :content %> 21 <%= form.rich_text_area :content %> 22 </div> 23 24 <div class="actions"> 25 <%= form.submit %> 26 </div> 27<% end %> 28
newHTMLerb
1<%= render "shared/header"%> 2 3<h1>New Post</h1> 4 5<%= render 'form', post: @post %> 6 7<%= link_to 'Back', posts_path %> 8 9<%= render "shared/footer"%>
postRB
1class Post < ApplicationRecord 2 has_rich_text :content 3 belongs_to :category 4 def self.search(search) 5 if search != "" 6 Post.where('text LIKE(?)', "%#{search}%") 7 else 8 Post.all 9 end 10 end 11end 12
postController
1class PostsController < ApplicationController 2 before_action :set_post, only: [:show, :edit, :update, :destroy] 3 before_action :move_to_index, except: [:index, :show] 4 before_action :search_post, only: [:index, :search] 5 6 # GET /posts 7 # GET /posts.json 8 def index 9 @posts = Post.includes(:user).order("created_at DESC") 10 end 11 12 # GET /posts/1 13 # GET /posts/1.json 14 def show 15 end 16 17 # GET /posts/new 18 def new 19 @post = Post.new 20 end 21 22 # GET /posts/1/edit 23 def edit 24 end 25 26 # POST /posts 27 # POST /posts.json 28 def create 29 @post = Post.new(post_params) 30 31 respond_to do |format| 32 if @post.save 33 format.html { redirect_to @post, notice: 'Post was successfully created.' } 34 format.json { render :show, status: :created, location: @post } 35 else 36 format.html { render :new } 37 format.json { render json: @post.errors, status: :unprocessable_entity } 38 end 39 end 40 end 41 42 # PATCH/PUT /posts/1 43 # PATCH/PUT /posts/1.json 44 def update 45 respond_to do |format| 46 if @post.update(post_params) 47 format.html { redirect_to @post, notice: 'Post was successfully updated.' } 48 format.json { render :show, status: :ok, location: @post } 49 else 50 format.html { render :edit } 51 format.json { render json: @post.errors, status: :unprocessable_entity } 52 end 53 end 54 end 55 56 # DELETE /posts/1 57 # DELETE /posts/1.json 58 def destroy 59 @post.destroy 60 respond_to do |format| 61 format.html { redirect_to posts_url, notice: 'Post was successfully destroyed.' } 62 format.json { head :no_content } 63 end 64 end 65 66 def search 67 @posts = @p.result.includes(:category) # 検索条件にマッチした商品の情報を取得 68 end 69 70 private 71 # Use callbacks to share common setup or constraints between actions. 72 def set_post 73 @post = Post.find(params[:id]) 74 end 75 76 # Only allow a list of trusted parameters through. 77 def post_params 78 params.require(:post).permit(:title, :content) 79 end 80 81 def move_to_index 82 unless user_signed_in? 83 redirect_to action: :index 84 end 85 end 86 87 def search_post 88 @p = Post.ransack(params[:q]) # 検索オブジェクトを生成 89 end 90end 91
試したこと
Rails 6にjQueryとBootstrap導入
Node.js, webpacker, yarnのインストール
よろしくお願いいたします。
あなたの回答
tips
プレビュー