質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails 6

Ruby on Rails 6は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

0回答

1075閲覧

リッチテキストが保存されない

sorata_toll

総合スコア19

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails 6

Ruby on Rails 6は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2020/11/16 10:08

編集2022/01/12 10:55

###環境
OS:Ubuntu server 20.04STL
Ruby:2.7.2
Rails:6.0.3.4

###状況
このブログを参考にリッチテキストを作成したところ、postしたものが表示されませんでした。postはできて、showで見れない感じです。titleは表示されます。よろしくお願いします。

###コンソールログ

console

1rails new blog 2cd blog 3bundle install 4bundle exec rails action_text:install 5bundle exec rails g scaffold post title:string 6bundle exec rails db:create 7bundle exec rails db:migrate 8rails s 9 10 11Rendered posts/show.html.erb within layouts/applicationEverything's up-to-date. Nothing to doStarted GET "/posts/7/edit" for 192.168.0.7 at 2020-11-16 18:49:05 +0900 12Cannot render console from 192.168.0.7! Allowed networks: 127.0.0.0/127.255.255.255, ::1 13Processing by PostsController#edit as HTML 14 Parameters: {"id"=>"7"} 15 Post Load (0.2ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT ? [["id", 7], ["LIMIT", 1]] 16 ? app/controllers/posts_controller.rb:72:in `set_post' 17 Rendering posts/edit.html.erb within layouts/application 18 ActionText::RichText Load (0.1ms) SELECT "action_text_rich_texts".* FROM "action_text_rich_texts" WHERE "action_text_rich_texts"."record_id" = ? AND "action_text_rich_texts"."record_type" = ? AND "action_text_rich_texts"."name" = ? LIMIT ? [["record_id", 7], ["record_type", "Post"], ["name", "body"], ["LIMIT", 1]] 19 ? app/views/posts/_form.html.erb:18 20 Rendered posts/_form.html.erb (Duration: 7.1ms | Allocations: 2367) 21 Rendered posts/edit.html.erb within layouts/application (Duration: 8.6ms | Allocations: 2739) 22[Webpacker] Everything's up-to-date. Nothing to do 23Completed 200 OK in 22ms (Views: 18.0ms | ActiveRecord: 0.3ms | Allocations: 7289)

###コード
#####blog/app/models/post

class Post < ApplicationRecord has_rich_text :body end

#####blog/app/controllers/posts_controller.rb

class PostsController < ApplicationController before_action :set_post, only: [:show, :edit, :update, :destroy] def post_params params.require(:post).permit(:title, :body) end # 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) end end

#####blog/app/views/posts/_form.html.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 %> <%= form.label :body %> <%= form.rich_text_area :body %> </div> <div class="actions"> <%= form.submit %> </div> <% end %>

#####blog/app/views/posts/show.html.erb

<p id="notice"><%= notice %></p> <p> <strong>Title:</strong> <%= @post.title %> </p> <%= @post.body %> <%= link_to 'Edit', edit_post_path(@post) %> | <%= link_to 'Back', posts_path %>

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問