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?
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:
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 However I could be way off.
Ok so my solution ended up being just to change the primary_key in the model:
self.primary_key = 'clock_no' And setting the return to json:
def show @employee = Employee.find(params[:id]) respond_to do |format| format.html format.json { render json: @employee } end end 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? nose back to the docs