title: Ruby on Rails Find By Field other than ID
body: <p>Ok again forget my noobiness in Rails, but I'm not finding this either.  Although I think this one might be because well.. it doesn't exist?</p>
  
  <p>Ok so I'm still playing with RoR and I added a controller for employee, pretty simple just a name, clock_no, and wage.  But what if I don't want to search for an employee by ID?  To me it would be easier for the user to search by clock number, but I'm not figuring out how that works.  I am assuming it has something to do with this line, more specificly the set_employee line:</p>
  
  <pre><code>private
  # Use callbacks to share common setup or constraints between actions.
  def set_employee
    @employee = Employee.find(params[:id])
  end
  
  # Never trust parameters from the scary internet, only allow the white list through.
  def employee_params
    params.require(:employee).permit(:name, :clock_no, :wage)
  end
  </code></pre>
  
  <p>However I could be way off. </p>
  
  <p>Ok so my solution ended up being just to change the primary_key in the model:</p>
  
  <pre><code>self.primary_key = 'clock_no'
  </code></pre>
  
  <p>And setting the return to json:</p>
  
  <pre><code>def show
  @employee = Employee.find(params[:id])
   respond_to do |format|
     format.html
     format.json { render json: @employee }
   end
  end
  </code></pre>
  
  <p>HOWEVER, I don't think this is really the end all solution, again my noobiness could be showing, but it seems kinda hockie to me.  My hold up would be what if you wanted to search by say name or something else that wasn't the primary key and was not able to change the primary key like in my case?   <em>nose back to the docs</em></p>