1

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.

3
  • angular-route.js should be used for ruting the url Commented Aug 6, 2014 at 9:08
  • My problem is: javascripts don't load. How can I laod all of scripts in my page when I use render :layout => 'application', :nothing => true in my application_controller.rb? Commented Aug 6, 2014 at 9:14
  • faced the same problem and found no solution so far. Commented Sep 14, 2014 at 15:29

1 Answer 1

0

This is what I would change in the assets/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

I had a similar problem and this the way I fixed it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.