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

wizard_path's "url_for" call throws ActionController::UrlGenerationError in mounted engine #179

Closed
fsauter opened this issue Jul 22, 2015 · 3 comments

Comments

@fsauter
Copy link

fsauter commented Jul 22, 2015

Hi together,

I tried to use wicked in my mounted engine but I always got errors like:

No route matches {:action=>"show", :controller=>"my_engine/contacts/contact_wizard", :id=>:type}

This happened here:
/home.rvm/rubies/ruby-2.2.2/lib/ruby/gems/2.2.0/gems/wicked-1.1.1/lib/wicked/controller/concerns/path.rb:28:in 'wizard_path'

So I fixed this by overriding the wizard_path method in my wizard controller. I replaced the url_for call with my engines routes method like this:

def wizard_path(goto_step = nil, options = {})
  options = { :controller => wicked_controller,
              :action     => 'show',
              :id         => goto_step || params[:id],
              :only_path  => true
  }.merge options
  # This line fixed it since the plain url_for does not know anything about the engine routes.
  MyEngine::Core::Engine.routes.url_for(options)
end

Now my question: Is there any best practice/better way to do this?

@schneems
Copy link
Member

I've never seen wicked used this way. Can you give me a barebones rails app with attached engine in a new github project so I can look into this further?

@fsauter
Copy link
Author

fsauter commented Aug 24, 2015

Sry @schneems, I don't find the time to setup a barebone app.

I think this is related to the following issue: rails/rails#6389

I had this issue with other gems as well (every gem that uses url_for).

The only gem that works is Devise (https://github.com/plataformatec/devise/wiki/How-To:-Use-devise-inside-a-mountable-engine#configuration). But I'm not experienced enough to figure out how they generate the urls (I think they don't use url_for at all to generate the urls).

I ended up by overriding/monkey patching ActionDispatch::Routing::UrlFor::url_for using an initializer:

def url_for options=nil
  begin
    super options
  rescue ActionController::RoutingError
    MyEngine::Core::Engine.routes.url_for options
  end
end

@schneems
Copy link
Member

I don't find the time to setup a barebone app.

I maintain this for free in my free time. However long it takes you to make an example app that reproduces your problem, it will take me 10x longer if I even can reproduce it. If I could write an app that breaks wicked, then I would have already fixed wicked. It's the most impactful thing you can do to help get this issue fixed.

I'm willing and happy to take a look, but you have to help me help you.

@schneems schneems closed this as completed Sep 2, 2016
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

2 participants