Referencing Model with String input

后端 未结 1 1739
感情败类
感情败类 2021-02-05 19:10

Lets say I wish to make a page that can query the desired object with type(string) and id(int).

/query?type=people&id=1

would fe

相关标签:
1条回答
  • 2021-02-05 19:45

    Try:

    klass = params[:type]
    klass.singularize.classify.constantize.find(params[:id])
    

    Edit:

    @object = params[:type].singularize.classify.constantize.find(params[:id])
    
    0 讨论(0)
提交回复
热议问题