Reputation: 10541
I can have a view file that contains only this:
root/app/views/layouts/application.html.erb
<%= link_to root_url %>
And of course it works. This is because
ActionController
is included in the view file somehow.
How does this work? Inside each view we don't write 'include ActionController' so how is it magically included?
Let's say I'm using an angular template:
root/app/assets/templates/angularview.html.erb
<%= link_to root_url %>
Everything works perfectly apart from the fact that the link_to isn't included in this view:
undefined method `link_to' for #<#<Class:0x000000020417b0>:0x0000000468f2c8>
Upvotes: 0
Views: 762
Reputation: 16002
It is not working as you have your angularview template in assets directory(as you have mentioned in your question: root/app/assets/templates/angularview.html.erb). You need to create it inside your application's app/views/layouts/ directory.
See these answers for more information:
UPDATE: However, if you must do that then you can create an initializer and put this code:
Rails.application.assets.context_class.class_eval do
include ActionView::Helpers
include MyAppHelper
include Rails.application.routes.url_helpers
end
Source: https://stackoverflow.com/a/14284279/645886
Upvotes: 1