I am currently learning Rails, and I want to use angular in my project.
Here's a simple application from scratch.
1). Create a new rails application:
rails new hello_rails
2). Add angular gem to gemfile
gem 'angularjs-rails'
3). Install package
bundle install
4). Add angular to javascript manifest in app/assets/javascripts/application.js
//=require angular
5). Create Welcome Index
rails generate controller welcome index
6). Fill out index.html.erb angular hello world
<div style = "background-color: grey"> this is index.html.erb<br> <div ng-app=""> <p>Name : <input type="text" ng-model="name"></p> <h1>Hello {{name}}</h1> </div> </div>
7). Also change application.html.erb
<pre> <!DOCTYPE html> <html> <head> <title>HelloRails</title> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> </head> <body style = "background-color:green"> This is application.html.erb <br> <%= link_to "click here to go home", root_path %> <br> A yeild statement is below: <br> <%= yield %> </body> </html>
eight). Set the root of the route to welcome#index in config/routes.rb
root 'welcome#index'
Run this - it works great.
Here we get:

Angular works:

However, if I click the link to return to root_path , it stops working

In addition, if we add angular to our application.html.erb , then the resulting angular will stop working.
<div ng-app=""> <p>Name : <input type="text" ng-model="home_name"></p> <h1>Hello {{home_name}} at home</h1> </div>

Can you explain why the rails work this way?