George Shaw
George Shaw

Reputation: 1781

Rails app routes not available in engine

I'm having the opposite problem of other related posts here. I'm using a gem that renders a page that uses the application's layout. That layout works fine in the application otherwise. In that layout is a named path, login_logout_path, that causes an undefined local or method error.

Here is a snippet of the view code:

<%= link_to( ApplicationName + ' Home', root_path ) %> |
<%= link_to('Sign Off', login_logout_path ) %> :
<%= get_session_login.iname %>

root_path works fine, logon_logout_path fails.

On complication might be that the layout above and the logon_logout_path is supplied by another gem that contains common code/layouts for the set of web sites.

Upvotes: 2

Views: 190

Answers (1)

joseramonc
joseramonc

Reputation: 1931

Short Answer, change

login_logout_path

with:

main_app.login_logout_path 

and add main_app to all your routes in the application.html.erb that go to your main app

Long answer: The problem is that engines can have routes with the same name as a route in your main app and work without crashing, if you want to use a route of your main app inside your engine you have to specify it putting

main_app.

Before the route, and if you want to use a route of your engine in your main app you have to specify it with

engineName.example_path

The root_path works because your engine has defined a root_path, and it's send you to the root path of the engine, not the one in your app, you can fix it with adding main_app before it too.

Upvotes: 3

Related Questions