Reputation: 110960
I would like a rails route that takes 2 constraints into consideration. How can this be done? The two constraints
match ':id' => 'pages#temp', :constraints => { :uuid => /[A-Za-z\d]([-\w]{,498}[A-Za-z\d])?/ }
root :to => 'pages#temp', :constraints => lambda {|r| r.env["warden"].authenticate? }
How can I have one route like so with both of the constraints in place? Thanks
match ':id' => 'pages#temp', :constraints =>
Upvotes: 6
Views: 4171
Reputation: 624
I had to use multiple constraints for subdomains and usernames. I used a block to solve the issues:
constraints subdomain: ['survey', 'survey.staging'] do
match "/(:username)", to: "responses#index", constraints: { username: /[0-z\.\-\_]+/ }, :via => [:get, :post]
end
So you might try something like this:
constraints id: { uuid: /[A-Za-z\d]([-\w]{,498}[A-Za-z\d])?/ } do
match '/:id' to: 'pages#temp', constraints: lambda {|r| r.env["warden"].authenticate? }
end
Upvotes: 1
Reputation: 537
I guess you will have to make a custom constraints class and put all your constraints there. Refer the advanced constraints in rails guides(Link below) for more information.
http://guides.rubyonrails.org/routing.html#advanced-constraints
Upvotes: 3