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

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

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

Haml(HTML abstraction markup language)は、HTML/XHTMLを効率的に記述するためのマークアップ言語および記法です。

Ruby on Rails 6

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

Sass

Sassは、プログラミング風のコードでCSSを生成できるスタイルシート言語です。 scss ファイルを、変換(コンパイル)してCSSファイルを作成します。

Q&A

解決済

1回答

591閲覧

Ruby on Rails6 ActiontextでNoMethodErrorが出る

ken1203

総合スコア24

Haml

Haml(HTML abstraction markup language)は、HTML/XHTMLを効率的に記述するためのマークアップ言語および記法です。

Ruby on Rails 6

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

Sass

Sassは、プログラミング風のコードでCSSを生成できるスタイルシート言語です。 scss ファイルを、変換(コンパイル)してCSSファイルを作成します。

0グッド

0クリップ

投稿2020/11/10 01:31

前提・実現したいこと

rails6で下記のリンクを参考にActiontextをインストールしました。
リンク内容

NoMethodError in Posts#new を解決したい。

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

http://localhost:3000/posts/_form NoMethodError in Posts#new Showing /Users/name/Dr_nishi/app/views/posts/_form.html.erb where line #25 raised: undefined method `rich_text_field' for #<ActionView::Helpers::FormBuilder:0x00007ff4612f4fd8> Did you mean? rich_text_area Extracted source (around line #25): 23 <div class="field"> 24 <%= form.label :content %> 25 <%= form.rich_text_field :content %> 26 </div> 27 <% end %>

該当のソースコード

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 %> </div> <div class="actions"> <%= form.submit %> </div> <div class="field"> <%= form.label :content %> <%= form.rich_text_field :content %> </div> <% end %>
posts/show.html.erb <p id="notice"><%= notice %></p> <p> <strong>Title:</strong> <%= @post.title %> </p> <%= link_to 'Edit', edit_post_path(@post) %> | <%= link_to 'Back', posts_path %> <%= @post.content %>
post/new.html.erb <h1>New Post</h1> <%= render 'form', post: @post %> <%= link_to 'Back', posts_path %>
posts/index.html.erb <p id="notice"><%= notice %></p> <h1>Posts</h1> <table> <thead> <tr> <th>Title</th> <th colspan="3"></th> </tr> </thead> <tbody> <% @posts.each do |post| %> <tr> <td><%= post.title %></td> <td><%= link_to 'Show', post %></td> <td><%= link_to 'Edit', edit_post_path(post) %></td> <td><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %></td> </tr> <% end %> </tbody> </table> <br> <%= link_to 'New Post', new_post_path %>
config/routes.rb Rails.application.routes.draw do resources :posts end
post.controlller.rb class PostsController < ApplicationController before_action :set_post, only: [:show, :edit, :update, :destroy] def index @posts = Post.all end def show end def new @post = Post.new end def edit end 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 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 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 def set_post @post = Post.find(params[:id]) end #def post_params #params.require(:post).permit(:title) #end def post_params params.require(:post).permit(:title, :content) end end

試したこと(仮説)

NoMethodError in Posts#new で検索しましたが初心者の私には
参考になるような文献を見つけることが出来ませんでしたので今回質問させていただきました。

補足

言葉足らずで申し訳ありませんがご教示頂けたらと思います。
宜しくお願い致します。

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

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

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

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

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

guest

回答1

0

ベストアンサー

追記

動画でもform.rich_text_fieldは利用されていないですね。

イメージ説明


仕様の変更があったのかまでは確認できていないですが、Railsガイドにはform.rich_text_areaと記載があるので、ひとまずこれでトライしてみてはいかがですか?

Ruby

1<%# app/views/messages/_form.html.erb %> 2<%= form_with(model: message) do |form| %> 3 <div class="field"> 4 <%= form.label :content %> 5 <%= form.rich_text_area :content %> 6 </div> 7<% end %>

https://railsguides.jp/action_text_overview.html

投稿2020/11/10 01:52

編集2020/11/10 02:01
no1knows

総合スコア3365

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

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

no1knows

2020/11/10 07:47

それは良かったです!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問