Cannot read property 'index' of undefined

Issue I am very new to Angular and was trying to use it on my Rails Application. But I got the following error. TypeError: Cannot read property ‘index’ of undefined app.js code angular.module(‘ticket’, [‘ngResource’, ‘ui.router’, ‘templates’]) .controller(‘AppCtrl’, [‘$rootScope’, function($rootScope) {

Continue reading

How to use CDN hosted highlight.js using Rails?

Issue Where do I place the following links to get highlight.js to work on my Rails application (https://highlightjs.org/download/)? <link rel=”stylesheet” href=”//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/default.min.css”> <script src=”//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/highlight.min.js”></script> Solution on app/views/layouts/application.html In the middle of head tags. Sometimes is hard to identify something in the

Continue reading

How can I convert erb to html?

Issue Imagine in rails I have @template that is an instance of ActionTemplate::View. Question is: How can I convert @template whose @template.source is <%= “hello from erb” %> to hello from erb?? thanks Solution Try this… ERB.new(@template.source).result ERB#new Answered By

Continue reading

Rails: form_for shortening code

Issue I am currently learning rails and I have the following code: <%= form_for(@account) do |f| %> <%= f.label :username %> <%= f.text_field :username, class: ‘form-control’ %> <%= f.label :email %> <%= f.email_field :email, class: ‘form-control’ %> <%= f.label :password

Continue reading

Understanding Rails with webpacker and incidence on JS

Issue A rails 6 application calls from a legacy application being migrated: <%= javascript_pack_tag ‘zxing.js’ %> <script type="text/javascript"> window.addEventListener(‘load’, function () { let selectedDeviceId; const codeReader = new ZXing.BrowserMultiFormatReader() console.log(‘ZXing code reader initialized’) codeReader.listVideoInputDevices() .then((videoInputDevices) => { const sourceSelect =

Continue reading

angular-rails-templates: templates are not found

Issue I have a rails application, using angularjs for the client side development. I try to load a template located in `app/assets/javascripts/templates/’: myApp.config([‘$routeProvider’, function($routeProvider) { $routeProvider. when(‘/’, { templateUrl: ‘/index.html’, controller: ‘MainController’ }). otherwise({ redirectTo: ‘/’ }); }]); but I

Continue reading

angularjs add a model layer

Issue I am using angular with rails backend and I am using $resource to interact backend API. so I have a User service which is a $resource instance App.factory(‘User’, [‘$resource’, function($resource) { return $resource(‘/users/:id’,{id: ‘@id’}); }]) Now I can use

Continue reading

rails created_at index isn't using index

Issue I have a model called CacheSync, mysql shows that it has an index: mysql> show indexes from cache_syncs; +————-+————+———————————+————–+————-+———–+————-+———-+——–+——+————+———+—————+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null

Continue reading

Why is my button not appearing on the page?

Issue I have this form in a partial: <%= form_for current_user.relationships.build(:followed_id => @profile.user.id) do |f| %> <div><%= f.hidden_field :followed_id %></div> <div class=”follow_button”><%= f.submit “Follow” %></div> <% end %> that is rendered to my profile view. Here is the resulting html:

Continue reading