Rails 3 Custom Route that takes multiple ids as a parameter

后端 未结 1 1988
天涯浪人
天涯浪人 2020-12-15 13:50

How do I add a route to my Rails 3 app which allows me to have a URL that maps to an action in a RESTful resource that accepts multiple parameters:

/modelnam         


        
相关标签:
1条回答
  • 2020-12-15 14:16

    You can setup a route that matches anything, then split the parameter inside your controller:

    resources :modelname do
      match 'compare/*path' => 'controller#compare_action'
    end
    
    # controller:
    def compare_action
      @modelname = Modelname.find(params[:path].split(','))
    end
    
    0 讨论(0)
提交回复
热议问题