Friday 13 March 2015

Sql Query on Param in ruby on rails

Ruby provide some use full method like singularize , classify, constantize by using this method we
are fetch data by sql query on params element.
suppose i fetch data by params[:id] and params[:controller] 

----------------------------------------------------------------------


@result = params[:controller].singularize.classify.constantize.where(id: params[:id]).first

This working on every controller its act like model for every controller like suppose.
if params[:controller] => ProjectsController then singularize is convert this in singular and constantize convert  string to Project.

  

No comments:

Salesforce CRM vs. Zoho: A Comparative Analysis

Introduction: Selecting the right customer relationship management (CRM) software is crucial for businesses seeking to streamline their sal...