I am attempting to use asset_path
during development in my Ruby on Rails 4 application via a javascript. In my javascript, I'm referencing an HTML file using something like:
<%= asset_path('templates/login/index.html.erb') %>"
The file physically resides in $RAILS_ROOT/app/assets/templates/login/index.html.erb
When my javascript tries to grab this file, though, it is catching a 'catchall' route I put together because my frontend is AngularJS and it is handling the "routing" for the application. Here is the log:
Started GET "/templates/login/index.html.erb" for 127.0.0.1 at 2013-07-30 11:20:43 -0400
Processing by HomeController#index as
Parameters: {"a"=>"templates/login/index.html"}
Rendered home/index.html.erb within layouts/application (0.0ms)
Completed 200 OK in 12ms (Views: 12.3ms | ActiveRecord: 0.0ms)
My routes.rb looks like the following:
App::Application.routes.draw do
devise_for :users
root :to => 'home#index'
namespace :api do
end
get '*a', to: 'home#index'
end
What's the best way to avoid this issue? How can I reference the template file in my javascript/angular project?
As I mentioned in comments below what I'm trying to achieve is to retrieve templates from the asset pipeline instead of having to go to the server to grab them. The additional round-trip doesn't make sense since they can be served at page load to make the app perceived as 'faster' when they're already cached. The issue here is that you still need to define a Rails route to match every route on Angular's side otherwise Rails will return a 404.