Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matching regex #11

Closed
guiocavalcanti opened this issue Feb 7, 2012 · 9 comments
Closed

Matching regex #11

guiocavalcanti opened this issue Feb 7, 2012 · 9 comments

Comments

@guiocavalcanti
Copy link

I defined my routes as follows:

Redu::Application.routes.draw do
  namespace 'api' do
    match '*anything', :to => 'api#routing_error'
  end
end
ActionDispatch::Routing::Translator.translate_from_file('lang/i18n-routes.yml')

When I try to run rake routes I get this error:

(in /Users/guiocavalcanti/workspace/work/redu)
** Invoke routes (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
can't convert Array into String
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/rack-mount-0.6.14/lib/rack/mount/regexp_with_named_groups.rb:31:in `initialize'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/rack-mount-0.6.14/lib/rack/mount/regexp_with_named_groups.rb:31:in `compile'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/rack-mount-0.6.14/lib/rack/mount/regexp_with_named_groups.rb:31:in `initialize'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/rack-mount-0.6.14/lib/rack/mount/regexp_with_named_groups.rb:25:in `new'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/rack-mount-0.6.14/lib/rack/mount/regexp_with_named_groups.rb:25:in `new'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/actionpack-3.0.10/lib/action_dispatch/routing/route.rb:25:in `initialize'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/actionpack-3.0.10/lib/action_dispatch/routing/route_set.rb:186:in `inject'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/actionpack-3.0.10/lib/action_dispatch/routing/route.rb:24:in `each'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/actionpack-3.0.10/lib/action_dispatch/routing/route.rb:24:in `inject'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/actionpack-3.0.10/lib/action_dispatch/routing/route.rb:24:in `initialize'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/actionpack-3.0.10/lib/action_dispatch/routing/route_set.rb:299:in `new'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/actionpack-3.0.10/lib/action_dispatch/routing/route_set.rb:299:in `add_route'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/rails-translate-routes-0.0.4/lib/rails-translate-routes.rb:195:in `translate'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/rails-translate-routes-0.0.4/lib/rails-translate-routes.rb:194:in `each'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/rails-translate-routes-0.0.4/lib/rails-translate-routes.rb:194:in `translate'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/rails-translate-routes-0.0.4/lib/rails-translate-routes.rb:193:in `each'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/rails-translate-routes-0.0.4/lib/rails-translate-routes.rb:193:in `translate'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/rails-translate-routes-0.0.4/lib/rails-translate-routes.rb:347:in `translate_from_file'
/Users/guiocavalcanti/workspace/work/redu/config/routes.rb:6

I'm trying to make a catch all route (inside api namespace) to rescue from RoutingError (see this reference for details).

@francesc
Copy link
Owner

francesc commented Feb 7, 2012

You'll probably want to setup the api routes only in english as I don't see the point to have it several languages. Define a new Redu::Application.routes.draw do below the translated block (see the readme in backend section).

Hope it helps.

@guiocavalcanti
Copy link
Author

I did what you suggested with no success:

Redu::Application.routes.draw do
  root :to => 'base#site_index', :as => :home
end

ActionDispatch::Routing::Translator.translate_from_file('lang/i18n-routes.yml')

Redu::Application.routes.draw do
  namespace 'api' do
    resources :environments, :except => [:new, :edit] do
      resources :courses, :except => [:new, :edit], :shallow => true
      resources :users, :only => :index
    end
    # ActionController::RoutingError
    match '*anything', :to => 'api#routing_error'
  end
end

The strange part is that when I remove the resources part everything works. Do you have any hints about that?

@francesc
Copy link
Owner

francesc commented Feb 7, 2012

Weird, as the gem shouldn't be doing anything with the second routing block.

Does it work if you remove: ActionDispatch::Routing::Translator.translate_from_file('lang/i18n-routes.yml') line?

@guiocavalcanti
Copy link
Author

Maybe the error is caused by the :except => [] part. I setup a fresh rails 3.0.11 project with this routes.rb file:

TranslateRoutesTest::Application.routes.draw do
  resources :environment, :except => [:index, :show]
end

ActionDispatch::Routing::Translator.translate_from_file('config/locales/i18n-routes.yml')

And the same error came out. Removing the except throws no error.

@guiocavalcanti
Copy link
Author

By the way, it works removing the line you told me.

@francesc
Copy link
Owner

francesc commented Feb 7, 2012

Maybe something was broken up when adding support to 3.1 and 3.2 I use plenty of except and only on resources on those versions and it works correctly.

If you're still using 3.0 maybe you want to give a try to https://github.com/raul/translate_routes the original gem we forked in order to have suport for 3.1 and 3.2

@bobbus
Copy link

bobbus commented Feb 8, 2012

I got the same errors on an application using Rails 3.0, it is probably because of this Rails version.

@francesc
Copy link
Owner

francesc commented Feb 9, 2012

@bobbus @guiocavalcanti did you try the orginal gem? https://github.com/raul/translate_routes it should work ok for you until you decide to switch to Rails 3.2

@guiocavalcanti
Copy link
Author

Yes, it worked fine for me. Thanks for the help. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants