Ruby provide some use full method like singularize , classify, constantize by using this method we
@result = params[:controller].singularize.classify.constantize.where(id: params[:id]).first
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:
Post a Comment