I have implemented Friendly IDs and right now I am having trouble associating the opportunities for a company by slug (I had this working fine by ID).
CompaniesController:
def show
@opportunities = Opportunity.where("company_id = ?", params[:id]).paginate(:page => params[:page], :per_page => 25)
end
The Opportunity model has a company_id column. (Company has_many Opportunities). So the above works perfectly is my URL is "companies/1".
Since I've implemented Friendly ID, I now have a "slug" column in my Company model. So essentially I need to match the Company ID to the Opportunity ID, then grab the slug?
I am trying something like this, but it is not working:
def show
@opportunities = Opportunity.where("company_id = ?", params[:id]).find(params[:slug]).paginate(:page => params[:page], :per_page => 25)
end
How should I actually be doing this?
Thanks.