I want use angularjs in rails. for this, I want deactive rails view and just use angularjs html file. I use angular-resource.min.js
for routing the url and then I create index
action in my application_controller
for deactiving the rails views. Rails view are deactive now, but none of scripts and angular file run in project and when server is start, I see a blanck page, html of this page is empty and javascripts doesn't load in page.
I have below code in this project:
Forums_controller.rb
:
class ForumsController < InheritedResources::Base
respond_to :json
end
comments_controller.rb
:
class CommentsController < InheritedResources::Base
belongs_to :forum
respond_to :json
end
application_controller
:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def index
render :layout => 'application', :nothing => true
end
end
config/rootes.rb
:
Simpleforum::Application.routes.draw do
resources :forums, :defaults => {format: :json} do
resources :comments, :defaults => {format: :json}
end
root to: 'application#index'
end
And I add all angularjs requirements to assets folder.
I use this gem:
gem 'inherited_resources'
gem 'bootstrap-sass'
gem 'quiet_assets'
gem 'angularjs-rails-resource', '~> 1.1.1'
angularjs app controller
:
app.js.erb
:
'use strict';
angular.module('app', ['ngResource'])
.config(['$routeProvider', function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {controller: 'ForumIndexController', templateUrl: '<%= asset_path('templates/index.html') %>'})
.when('/forum/new', {controller: 'ForumCreateController', templateUrl: '<%= asset_path('templates/new.html') %>'})
.when('/forum/:id', {controller: 'ForumShowController', templateUrl: '<%= asset_path('templates/show.html') %>'})
.otherwise({redirectTo: '/'});
}
]);
application.js
:
//= require jquery
//= require jquery_ujs
//= require angularjs/rails/resource
//= require angularjs/rails/resource/extensions/snapshots
//= require angular.min
//= require angular-resource.min
//= require ../angular/app
//= require_tree ../angular
Where is the problem? How can I fixed this error?
Note
: I use this tutorial for create this project.
render :layout => 'application', :nothing => true
in myapplication_controller.rb
?