[Ruby] Let’s create an instance with .new yourself. .. ..

less than 1 minute read

Let’s create an instance with #.new yourself. .. ..

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

Screenshot 2020-07-19 2.41.05.png

While implementing the comment function Now I’m stuck.

![Screenshot 2020-07-19 2.42.24.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/653545/c929b8d7-2233-b6ca-e77c-(5ec98a693ad3.png)

””=>{“content_id”=>”468”, “comment”=>”Oh””,

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

```controller strong parameter def comment_params Params.require(:comment).permit(:comment, :content_id) end

There is no problem with permit.
There is no key to be in pramas.require?

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

Actually, I was stuck in the same place before, and I forgot and made the same mistake.

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

Since I was working on the show page of the timeline function this time,

#### **`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!

![Screenshot 2020-07-19 2.50.24.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/653545/668d20a0-e0e1-c4b0-966d-(038428f0af49.png)

“comment”=>{“content_id”=>”468”, “comment”=>”Ah”},

The parameter key is out! !!


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

Thank you very much.