Let's create an instance with .new yourself. .. ..

Let's create an instance with .new yourself. .. ..

Without the parameter key of the strong parameter that I do a little bit? problem

スクリーンショット 2020-07-19 2.41.05.png

While implementing the comment function Now it's jammed.

スクリーンショット 2020-07-19 2.42.24.png

"=> {" content_id "=>" 468 "," comment "=>" Ah "},

why? And looking at the parameters, the values are being sent. .. .. Next, check the destination controller.

def comment_params
  params.require(:comment).permit(:comment, :content_id)
end

permit is fine. Hmm? There is no key to be in pramas.require, right?

This → "" => {"content_id" => "468", "comment" => "Ah"},

Actually, I got stuck in the same place before and forgot to make the same mistake.

The answer is simple, just instantiate with the controller on the current page I'm a big fool (laughs)

This time I was working on the show page of the timeline function, so

time_line_controller.rb


  def show
    @content = Content.find(params[:id])
    @user = User.find(@content.user_id)
    @comment = Comment.new #I added this.

Add the above and try again!

スクリーンショット 2020-07-19 2.50.24.png

"comment" => {"content_id" => "468", "comment" => "Ah"},

I got a parameter key! !!

Conclusion

Don't forget to create an instance on the current page even after creating a new model! that's all.

Thank you very much.

Recommended Posts

Let's create an instance with .new yourself. .. ..
Create an immutable class with JAVA
Let's create Ubuntu environment with vmware
Create an app with Spring Boot 2
Create an excel file with poi
Create an app with Spring Boot
Create an infinite scroll with Infinite Scroll and kaminari
[Java] Create an executable module with Gradle
[Rails6] Create a new app with Rails [Beginner]
Create a temporary class with new Object () {}
[Rails 5] Create a new app with Rails [Beginner]
Create an or search function with Ransack.
Let's make an error screen with Rails
Let's create JUnit.
[Rails] rails new to create a database with PostgreSQL
Let's create a timed process with Java Timer! !!
Create an RSA encryption-enabled JSON API with wicket
Create related data together with FactoryBot for yourself
Let's quickly create an app that uses Firestore! !!
Create an EC site with Rails5 ⑤ ~ Customer model ~
Create an Annotator that uses kuromoji with NLP4J [007]
[Swift] Create an image selection UI with PhotoKit
Create an EC site with Rails 5 ⑩ ~ Create an order function ~
Create an HTTPS file server for development with ring-jetty-adapter
Create an EC site with Rails5 ⑦ ~ Address, Genre model ~
Create an EC site with Rails 5 ⑨ ~ Create a cart function ~
Create an EC site with Rails5 ④ ~ Header and footer ~
Create an E2E test environment with Docker x Cypress
Create a user with an empty password on CentOS7
Create an EC site with Rails5 ⑥ ~ seed data input ~
Create a Service with an empty model Liferay 7.0 / DXP
Try create with Trailblazer
A new employee tried to create an authentication / authorization function from scratch with Spring Security
Let's scrape with Java! !!
[Rails] Create an application
Maybe it works! Create an image with Docker and share it!
Create an AWS IoT EduKit development environment with Ubuntu 20.04 + VirtualBox 6.1
How to create an application server on an EC2 instance on AWS
[Rails] Create an email sending function with ActionMailer (complete version)
Initialization with an empty string to an instance of Java String type
What happens to instance variables when copying an instance with ruby