URL PARAMETER ACQUISITION METHOD FOR NESTER

Asked 2 years ago, Updated 2 years ago, 38 views

I would like to obtain low from the following URL, but if anyone knows how to do it, please let me know.

URL: http://100.100.100/test/site/page/1?money%5Bgo_to%5D=low

Also, the place to retrieve will be in before_save.

Below is the verified acquisition code.None of them moved.
params[:money.go_to]
params[:money][:go_to]

ruby-on-rails ruby

2022-09-30 19:56

1 Answers

If before_save refers to the callback of the model, you cannot see params from there.

You can also define attributes in the model that do not correspond to columns in the database.It is recommended that the controller take the value from the params and pass the value through it.The attributes corresponding to the columns in the database are almost the same, except that they are not stored in the database.

class User<...
  attribute:hoge
end

@user=User.new
user.hoge=params [:money] [:go_to]


2022-09-30 19:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.