angularjs - UI Router and Rails: Template is Missing -


i creating application rails , angular. using ui.router. when visit route via ui-sref link, loads. however, if refresh page, following error:

missing template posts/show, application/show {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder]}. 

the home page (root of site) not have problem. also, if type in url, /posts/1, same message, if click ui-sref link post, page load. (though refreshing page break it.) behavior might shed light on misconfiguration can click ui-sref link route /login – route undefined on rails side, defined in angular routes (app.js). however, when try reach /login other means, or if refresh /login, error: 'no route matches [get] "/login"'

routes.rb

rails.application.routes.draw   devise_for :users, :skip => [:registrations]   root to: 'application#angular'    resources :posts, only: [:create, :index, :show, :update, :destroy]     resources :comments, only: [:show, :create]       member         put '/upvote' => 'comments#upvote'         put '/downvote' => 'comments#downvote'       end     end      member       put '/upvote' => 'posts#upvote'       put '/downvote' => 'posts#downvote'     end   end    resources :users, only: [:show], to: 'users#show', via: 'get', layout: false end 

application_controller.rb

class applicationcontroller < actioncontroller::base   protect_from_forgery with: :exception    respond_to :json, :html    before_action :configure_permitted_parameters, if: :devise_controller?    def angular     render 'layouts/application'   end    private   def configure_permitted_parameters     devise_parameter_sanitizer.for(:sign_up) << :username   end end 

posts_controller.rb

class postscontroller < applicationcontroller     def show         respond_with post.find(params[:id])     end end 

app.js

angular.module('appname', ['ui.router', 'templates', 'devise', 'ui.bootstrap', 'angularmoment']) .config([   '$stateprovider',   '$urlrouterprovider',   '$locationprovider',   function($stateprovider, $urlrouterprovider, $locationprovider) {     $locationprovider.html5mode({       enabled: true,       requirebase: false     });     $stateprovider       .state('home', {         url: '/',         templateurl: 'home/_home.html',         controller: 'mainctrl',         resolve: {           postpromise: ['posts', function(posts){             return posts.getall();           }]         }       })       .state('posts', {         url: '/posts/{id}',         templateurl: 'posts/_posts.html',          controller: 'postsctrl',         resolve: {           post: ['$stateparams', 'posts', function($stateparams, posts) {             return posts.get($stateparams.id);           }]         }       })       //more stuff here       .state('login', {         url: '/login',         templateurl: 'auth/_login.html',         controller: 'authctrl',         onenter: ['$state', 'auth', function($state, auth) {           auth.currentuser().then(function (){             $state.go('home');           })         }]       })       .state('register', {         url: '/register',         templateurl: 'auth/_register.html',         controller: 'authctrl',         onenter: ['$state', 'auth', function($state, auth) {           auth.currentuser().then(function (){             $state.go('home');           })         }]       });     $urlrouterprovider.otherwise('home') }]) 

posts.rb (factory)

angular.module('appname')   .factory('posts', [     '$http',     function($http){     var o = {       posts: [],     };      o.get = function(id) {       return $http.get('/posts/' + id + '.json').then(function(res){         return res.data;       });      return o;   }]) 

my guess needs changed in configuration on angular side.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -