Home>
I am currently creating a web page with Rails.
There are multiple forms that are displayed by turning each do in the page, and the name of hidden_field in it is "XXXX _ # {post.id}".
When POST is performed in this state, the params value will be changed in the form of params [: XXXX_3] or params [: XXXX_25]. I can't get it.
Is it possible to get the value of params with the controller using a method like the prefix of XXXX?
I would appreciate it if you could teach me the right way.
Thank you.
<% = form_with (model: @user_info, url: "/ xxx/yyy", local: true) do | f |%>
<% = f.hidden_field "XXXX _ # {post.id}",: value =>''%>
<% = f.submit 'Send', id: 'submit_btn'%>
<% end%>
-
Answer # 1
-
Answer # 2
<% = f.hidden_field "XXXX",: value =>post.id%>
If
If you change the view side like,
xxxx_key = nil # Lick all keys and if key starts with xxxx params.each do | key, value | if key.start_with? ("xxxx_") xxxx_key = key break end end if xxxx_key.nil? # Error handling end puts xxxx_key
You can force it out if you do
Since strong parameters cannot be used, you must write your own validation when nil↑ I'm sorry if I had a grammar mistake because I didn't move it
Related articles
- ruby - [rails] about partial templates
- ruby - partial template is not displayed (rails)
- ruby on rails - i want to change only a part of the partial template
- ruby - [rails] parameter transmission is not executed properly after installing bootstrap
- ruby on rails - i want to reflect the partial template only when i am logged in
- ruby on rails - variables are not passed to the partial template without reloading
- ruby on rails - things associated with a foreign key cannot be called in view
- ruby on rails - saved description in nested controller
- ruby on rails - cart function routing error cannot be resolved
- ruby on rails - rails s can't
- ruby on rails - how to transition from the top page
- ruby on rails - i want to implement a function for administrator users to register luggage for general users in rails
- ruby - the last db setting doesn't work when deploying rails app on aws
- ruby - rails tutorial chapter 2 (6th edition)
- ruby on rails 5 - actioncontroller :: invalidauthenticitytoken cannot be resolved
- ruby on rails - error in controller when transitioning with rails6 destory action
- ruby on rails - access fails after seed after deploying to heroku
- ruby on rails runtime error cannot be resolved
- ruby on rails - missing required keys: i'm having trouble resolving the [: id] error
- ruby on rails 5 - some items are not saved in db when posting from rails form
Trends
Since [: XXXX_3] can be obtained with ["XXXX_3"], the same result can be obtained, so put the character string that combines the original id (the _3 part) with XXXX in []. It was solved with.