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

    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.

  • Answer # 2

    <% = f.hidden_field "XXXX",: value =>post.id%>

    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
    if xxxx_key.nil?
      # Error handling
    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