Ruby on rails rails中的Angularjs:angularjsjavascripts-don';t载荷
我想在rails中使用angularjs。为此,我需要DeactiveRails视图,只需使用angularjs html文件。我使用Ruby on rails rails中的Angularjs:angularjsjavascripts-don';t载荷,ruby-on-rails,angularjs,Ruby On Rails,Angularjs,我想在rails中使用angularjs。为此,我需要DeactiveRails视图,只需使用angularjs html文件。我使用angular resource.min.js路由url,然后在application\u controller中创建index操作以取消rails视图的激活。Rails视图现在是非活动的,但并没有脚本和角度文件在项目中运行,当服务器启动时,我看到一个blank页面,这个页面的html是空的,javascripts并没有加载到页面中 我在这个项目中有以下代码: 论
angular resource.min.js
路由url,然后在application\u controller
中创建index
操作以取消rails视图的激活。Rails视图现在是非活动的,但并没有脚本和角度文件在项目中运行,当服务器启动时,我看到一个blank页面,这个页面的html是空的,javascripts并没有加载到页面中
我在这个项目中有以下代码:
论坛(controller.rb):
class ForumsController < InheritedResources::Base
respond_to :json
end
class CommentsController < InheritedResources::Base
belongs_to :forum
respond_to :json
end
Simpleforum::Application.routes.draw do
resources :forums, :defaults => {format: :json} do
resources :comments, :defaults => {format: :json}
end
root to: 'application#index'
end
'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: '/'});
}
]);
应用程序\u控制器
:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def index
render :layout => 'application', :nothing => true
end
end
我将所有angularjs需求添加到assets文件夹中
我用这个宝石:
gem 'inherited_resources'
gem 'bootstrap-sass'
gem 'quiet_assets'
gem 'angularjs-rails-resource', '~> 1.1.1'
angularjs应用程序控制器
:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def index
render :layout => 'application', :nothing => true
end
end
app.js.erb
:
class ForumsController < InheritedResources::Base
respond_to :json
end
class CommentsController < InheritedResources::Base
belongs_to :forum
respond_to :json
end
Simpleforum::Application.routes.draw do
resources :forums, :defaults => {format: :json} do
resources :comments, :defaults => {format: :json}
end
root to: 'application#index'
end
'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: '/'});
}
]);
问题在哪里?如何修复此错误
注意
:我用于创建此项目。这是我将在资产/javascript/application.js中更改的内容:
//= require jquery
//= require jquery_ujs
//= require angular.min <-----------(*)
//= require angularjs/rails/resource
//= require angularjs/rails/resource/extensions/snapshots
//= require angular-resource.min
//= require ../angular/app
//= require_tree ../angular
/=需要jquery
//=需要jquery\u ujs
//=require angular.min angular-route.js应用于urlMy问题是:javascripts不加载。当我在application\u controller中使用render:layout=>'application',:nothing=>true
时,如何加载页面中的所有脚本。rb
?遇到了同样的问题,目前还没有找到解决方案。