エラー unknown attribute 'text' for Comment.
解決したいこと
・チャット投稿機能実装
ActionCableを用いて、リアルタイムチャットアプリを作成したいのですが、下記のエラーが発生しております。
勉強し始めて、1ヶ月ともあり、みなさまのご指導をいただきたいです。
よろしくお願いいたします。
発生している問題・エラー
該当するソースコード
app/controllers/homeromms_controller.rb
class HomeroomsController < ApplicationController
def index
@comments = Comment.all
@teachers = Teacher.all
end
def create
@comment = Comment.new(text: params[:comment])
if @comment.save
ActionCable.server.broadcast 'comment_channel', content: @comment
end
end
private
def comment_params
params.permit(:comment).merge(student_id: current_student.id)
end
end
app/views/homeromms/index.html.erb
<div class="main-container">
<div class="container">
<div class="comments_lists">
<% @comments.each do |comment| %>
<div class="message-date">
<%= l comment.created_at %>
</div>
<div class="message-comment">
<%= comment.comment %>
</div>
<% end %>
</div>
</div>
</div>
app/models/comment.rb
class Comment < ApplicationRecord
belongs_to :student
end
app/javascript/comment_channel.js
import consumer from "./consumer"
consumer.subscriptions.create("CommentChannel", {
connected() {
},
disconnected() {
},
received(data) {
const html = `<p>${data.content.comment}</p>`;
const comments = document.getElementById('comments');
const newComment = document.getElementById('comment_text');
comments.insertAdjacentHTML('afterbegin', html);
newComment.value='';
}
});
自分で試したこと
・カラム名の記述が間違えているか※こちらの記事を調べました(https://qiita.com/Ayaka_ramens/items/f0c68b08fcf6145c2b17)
0 likes