Default condition for `with` option for action defaults to .* #933

maca opened this Issue Sep 14, 2012 · 8 comments


None yet

5 participants


For this action

get(:users, with: :id) { ... }

This route matches


Shouldn't the condition default to /\w+/ or /[^/]+/ instead of apparently /.*/?

How do I set conditions for with option for controller actions?

Thanks for Padrino! :)


I was also wondering if such an option is available, this really could be useful :)


The problem I am having is that "/users//" is matching get(:users, with: :id) when I think it shouldn't since :id is not provided.
I can give it a shot.

In regards to passing conditions how about this get(:users, :id => /\d+/) ?
I could give it a shot too.

Padrino Framework member

You can also break into a more explicit path definition with:

get :users, :map => /users/(\d+)/ do


for the desired effect. But I could see why you'd prefer :id not to be matched if it was a blank value.


Yeah, I definitelly would expect blank :id not to be matched. If you are ok I could dig.

I guess I can get a captured param with this:

 get(:users, map: /users/(?<id>\d+)/) {...} 

Kind of looks ugly though.


Correct me if I'm wrong but when defining routes with a regexp to catch parameters, the helper url fails.


App.controllers :test do
  get :index, :map => '/user/(\d+)' do
    puts 'test'

  get :index_id, :map => '/user/:id' do
    puts 'test'
url(:test, :index, 3);
# won't work
url(:test, :index_id, :id => 3);
# works
Padrino Framework member

You need to use a regex:

get :index, :map => %r{/user/(\d+)} do; end

Even with a regex, the route isn't found by the helper method url

I did a little research and found out that you can specify a matching condition on named parameters.

get :index, :map => '/index/:id', :matching => {:id => /\d+/} do
  url(:test, :index, :id => 42)

displays /index/42 and throw an error if id is not a integer.

@ujifgc ujifgc added a commit to ujifgc/padrino-framework that referenced this issue Jan 12, 2013
@ujifgc ujifgc Add test for #933 ed9abb0
Padrino Framework member

This issue is resolved on edge. Please reopen if it's not.

@ujifgc ujifgc closed this Jan 12, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment