title: How to use find method for composite primary keys in ruby on rails?
body: <p>I have a table called <code>SubElement</code>.</p>
  
  <p>It has two primary keys : <code>Element_Code, Sub_Element_Code</code></p>
  
  <p>In my view, when i try to do something like the following</p>
  
  <pre><code>&lt;% 
    sub_element_model = Condition::SubElement
    sub_element = @sub_element_code.nil? ? sub_element_model.new : sub_element_model.find(@sub_element_code)
    if sub_element.persisted?
      @element_code = sub_element.Element_Code
      f.object.Sub_Element_Code = @sub_element_code
    end
  %&gt;
  </code></pre>
  
  <p>I got an error after selected the sub_element_value like </p>
  
  <pre><code>["4"]: Incorrect number of primary keys for Condition::SubElement: [:Element_Code, :Sub_Element_Code]
  </code></pre>
  
  <p>How can i use the find method for two composite primary keys. </p>
  
  <h2>Update:</h2>
  
  <p>In the form, I have <code>element_code field, sub_element_code and material</code>. But everything should visible once the parent selected. With the help of some javascript I try to finish this. The Main problem of what I could not explain in detail is the form fields are creating by some helper file. It's a very large file and i cant change that. So I am looking for the alternative solution to change the find method for the two composite primary keys to get the value. </p>