title: Ruby - Extract value of a particular key from array of hashes
body: <p>I have an array of hashes - @profiles which has data as:</p>
  
  <pre><code>[{:user_id=&gt;5, :full_name=&gt;"Emily Spot"},{:user_id=&gt;7, :full_name=&gt;"Kevin Walls"}]
  </code></pre>
  
  <p>I want to get full_name of say user_id = 7? I'm doing the following: but it's throwing an error that expression <code>@profiles.find{|h| h[':user_id'] == current_user.id}</code> is nil.</p>
  
  <pre><code>name = @profiles.find{ |h| h[':user_id'] == current_user.id }[':full_name']
  </code></pre>
  
  <p>if I use <code>select</code> instead of <code>find</code> then error is - no implicit conversion of String into Integer.</p>
  
  <p>How do I search through the array of hashes?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>After @Eric's answer, I restructured my job model &amp; view actions:</p>
  
  <pre><code>  def full_names
      profile_arr||= []
      profile_arr = self.applications.pluck(:user_id)
      @profiles = Profile.where(:user_id =&gt; profile_arr).select([:user_id, :first_name, :last_name]).map {|e| {user_id: e.user_id, full_name: e.full_name} }
      @full_names = @profiles.each_with_object({}) do |profile, names|
        names[profile[:user_id]] = profile[:full_name]
      end
    end
  </code></pre>
  
  <p>In the view....,</p>
  
  <pre><code>p @current_job.full_names[current_user.id]
  </code></pre>