Home>

The comment function is implemented in ruby ​​on rails.

For each user's post, I want to create a post detail page and display the comment input field and the comment content and the commented user name below it.

Pressing the post comment button does not cause an error, but the comment is not displayed.
There is a description of Unpermitted parameter :: content on the console.

Corresponding source code

comment.rb

class Comment</pre>
<pre><code>class CommentsController</pre>
<p><br />
comment_controller.rb</p>
<p>Comment detail page (VIEW)</p>
<pre><code>
<% = form_with (model: [@micropost, @comment], local: true) do | f |%>
    
    <% = f.text_area: content%>
    
  <% = f.submit "comment", class: "btn btn-primary"%>
<% end%>


<% @ micropost.comments.each do | comment |%>
  <p>
    <% = @ comment.content%>
  </p>
<% end%>


route.rb

Rails.application.routes.draw do
  root'static_pages # home'
  get'/ help', to:'static_pages # home'
  get'/ account', to:'static_pages # account'
  get'/ signup', to:'users # new'
  get'/ login', to:'sessions # new'
  post'/ login', to:'sessions # create'
  delete'/ logout', to:'sessions # destroy'
  resources: users
  resources: password_resets, only: [: new,: create,: edit,: update]
  resources: microposts, only: [: create,: destroy,: show] do
    resources: comments, only: [: create,: destroy]
  end
end
What I tried

I have confirmed that comment.new and comment.create can be created on the console.

Supplementary information (FW/tool version, etc.)

The environment is as follows.
Rails 6.0.3.4
ruby 2.7.1p83
I am using vscode.
The personal computer is mac book air.
I started learning programming, but I'm having trouble displaying comments.
I checked the source code on the internet of many people and tried it, but I couldn't display it and asked a question here.
Thank you very much.

Please provide more detailed information here.

  • Answer # 1

    <% = @ comment.content%>→<% = comment.content%>
    how is?

Related articles