Anatortoise
unread,Mar 31, 2011, 7:53:50 PM3/31/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to refine...@googlegroups.com
Answering my own question, in case someone else needs it.
General problem: a gem adds routes, loaded after main app, that conflict with and override main app named routes. So recognize_path and url_helpers no longer agree.
Specific to refinerycms, if you are integrating with existing app that already uses devise, and need the main app devise routes rather than refinerycms devise routes...
A Solution:
Create MainApp/config/named_routes_overrides.rb containing..
Rails.application.routes.draw do
#re-state the necessary routes here, in addition to stating them higher in routes.rb , sandwiching the conflicting gem route definitions above and below.
devise_for :users, :controllers=>{:sessions=>"users/sessions"} do
get "users/sessions/whatever" #example additional routes handled by custom session controller
end
end
Add the following inside MainApp/config/application.rb
class Application < Rails::Application
...
initializer 'add named route overrides' do |app|
app.routes_reloader.paths << File.expand_path('../named_routes_overrides.rb',__FILE__)
#this seems to cause these extra routes to be loaded last, so they will define named routes last.
end
end
Test with rails console, before the fix, named routes don't match recognize path:
>Rails.application.routes.url_helpers.destroy_user_session_path
=> "/registrations/logout" #refinerycms named route
>Rails.application.routes.recognize_path("/users/sign_out")
=> {:controller=>"users/sessions", :action=>"destroy"}
After fix, they match:
>Rails.application.routes.url_helpers.destroy_user_session_path
=>"/users/sign_out"
Rails.application.routes.recognize_path("/users/sign_out")
=> {:controller=>"users/sessions", :action=>"destroy"}