{"id":284,"date":"2012-12-24T10:51:33","date_gmt":"2012-12-24T18:51:33","guid":{"rendered":"http:\/\/www.antunkarlovac.com\/blog\/?p=284"},"modified":"2012-12-24T10:51:33","modified_gmt":"2012-12-24T18:51:33","slug":"requirements-method-for-rails-3-routes","status":"publish","type":"post","link":"https:\/\/www.antunkarlovac.com\/blog\/2012\/12\/24\/requirements-method-for-rails-3-routes\/","title":{"rendered":":requirements Method for Rails 3 Routes"},"content":{"rendered":"<p>In Rails 2, if you wanted to have a parameter on a URL that had a period (e.g. a decimal point in latitude\/longitude coordinates), you needed to use the :requirements method to tell Rails to include everything in the URL.<\/p>\n<p>e.g.if your URL was \/spots\/new_popup\/37.77617617425586,-122.39735126495361<\/p>\n<p>&#8230; then the Rails 2 route would look like this:<\/p>\n<pre class=\"brush: ruby; title: ; notranslate\" title=\"\">\r\nmap.connect '\/spots\/new_popup\/:coords', :requirements =&gt; {:coords =&gt; \/.*\/}, :controller =&gt; 'spots', :action =&gt; 'new_popup'\r\n<\/pre>\n<p>In Rails 3, there :requirements method has been replaced with :constraints. So the route above would be re-written like this:<\/p>\n<pre class=\"brush: ruby; title: ; notranslate\" title=\"\">\r\nmatch '\/spots\/new_popup\/:coords', :constraints =&gt; {:coords =&gt; \/.*\/}, :controller =&gt; 'spots', :action =&gt; 'new_popup'\r\n<\/pre>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>In Rails 2, if you wanted to have a parameter on a URL that had a period (e.g. a decimal point in latitude\/longitude coordinates), you needed to use the :requirements method to tell Rails to include everything in the URL. e.g.if your URL was \/spots\/new_popup\/37.77617617425586,-122.39735126495361 &#8230; then the Rails 2 route would look like this: &hellip; <a href=\"https:\/\/www.antunkarlovac.com\/blog\/2012\/12\/24\/requirements-method-for-rails-3-routes\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">:requirements Method for Rails 3 Routes<\/span><\/a><!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/posts\/284"}],"collection":[{"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/comments?post=284"}],"version-history":[{"count":6,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/posts\/284\/revisions"}],"predecessor-version":[{"id":290,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/posts\/284\/revisions\/290"}],"wp:attachment":[{"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/media?parent=284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/categories?post=284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/tags?post=284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}