M
M
Max2015-06-06 13:55:31
Angular
Max, 2015-06-06 13:55:31

How to include a JS controller in Rails?

Hello, please tell me how to connect the Angular controller and the Angular itself to the rails.
I want to figure out how to combine these two frameworks, but so far it’s not very good.
With the command "rails g controller home index" I create a view and a controller. But the controller has a .rb extension, if I rename it to js.cofee, then the rails advise to initialize the controller with "uninitialized constant HomeController" .
And if in a standard controller (that is, where .rb) I write

@homeCntl = ($scope) -> 
  $scope.enterNames = [
    {name: "Max"},
    {name: "Bob"}
  ]
That he naturally does not understand this code.
Angular works if the controller is not used.
Oh yeah, and here is the controller call
<div ng-controller="homeCntl">
 	<ul>
 		<li ng-repeat="entryName in enterNames ">
 			{{entryName.name}}
 		</li>
 	</ul>
 </div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jeiwan, 2015-06-06
@maxprof

Better leave aside for now these ideas about combining Angular and Rails and just read rusrails.ru , study rails yourself. Well, in general, take some time to figure out how the browser interacts with the HTTP server in general. Judging by the question, you have absolutely no idea what you are doing, and any attempts to continue working with these frameworks will only create problems.
And if, in essence, the Angular and Rail controllers are "combined" through HTTP requests: the angular controller accesses the angular service, which sends an asynchronous request to the rail server, in which this request falls into one or another controller.
Angular and Rails are two different frameworks, written in different languages, working on different sides of the barricade: Angular is on the front end (in the user's browser), Rails is on the back end (on the server of the bearded admin). How can a browser interact with an HTTP server? Only through HTTP requests.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question