...callback this list might help you to fix your code afterwards: attribute_changed? will return true in the after_save callback and false in the after_commit callback. Use something...
...path like "./foo.coffee". // The call to "substring" removes the "./" prefix. let preparePath = function(filePath) { return filePath.substring(2); }; modelFiles = require.context('js/models', true, /\.(js|coffee)$/); for(let filePath of modelFiles.keys()) { import(`js/models...
...secret folder with its contents. def migrate! correct_store_path = Pathname.new(new_store_dir) return if correct_store_path.directory? # already moved if the directory exists, nothing to do parent_path = correct_store_path.parent # this...
The Angular 1.2 way: # By default, angular returns undefined for invalid attributes which removes # the value from the form field's ngModel (which means it's not sent to the...
...not be overwritten). # # This directive makes sure that form fields with an invalid value return an # empty string instead of undefined. for elementType in ['input', 'textarea', 'select'] @app.directive elementType, ->
...as described in the documentation. For example load ace Editor like this: function loadAceEditor() { return import(/* webpackChunkName: "ace" */ 'ace-builds/src-noconflict/ace').then(() => { return import(/* webpackChunkName: "ace" */ 'ace-builds/webpack-resolver.js') }) }
...and sync any changes into the textarea. $element.hide() session.setValue($element.val()) session.on('change', () => { $element.val(session.getValue()) }) return () => { editor.destroy...
If you do not provide a block to find_each, it will return an Enumerator for chaining with other methods: Person.find_each.with_index do |person, index| person.award_trophy(index...
...of the weekday in Ruby as defined by ISO 8601, use Date#cwday, which returns values in 1..7 (mind the range difference to Date#wday). The first week of...
...the calendar week in Ruby as defined by ISO 8601, use Date#cweek, which returns values in 1..53 USA and Canada Not defined in a standard. Weeks start on...
...both its group and its group_id: user = User.find(1) user.group = Group.find(3) user.group # returns # user.group_id = 4 user.group_id # returns 4 user.save After the save, the change to group...
...id will be lost: user.group # returns # user.group_id # returns...
With this, the scope chain Meal.for_date(Date.today).suitable_for(current_user) would return all meals, not only those of today. Do this instead: def self.suitable_for(user)
...for Rails 2 use `scoped({})` instead of `all` end end Note how we're returning #all instead of self. This ensures that we're preserving the upstream scope chain...
>> user.errors.of_kind?(:email, :taken) => true Using added? without specifying options will return false: >> user.errors.added?(:email, :taken) => false >> user.errors.added?(:email, :taken, value: "user@example.com") => true Most often, you probably...
Returning an empty scope can come in handy, e.g. as a default object. In Rails 4 you can achieve this by calling none on your ActiveRecord model. MyModel.none # returns an...
...doesn't, and that's what causes pain. The method is defined as follows: # Returns whether or not +file+ is a binary file. Note that this is # not guaranteed to...
...raised for characters that are undefined in UTF-8. def is_file_binary?(path) return false unless File.binary?(path) content = File.read(path) content&.encode('UTF-8', 'binary') true rescue Encoding...
...folders, you might consider setting this keyboard to "Copy From Repository Root". This will return the path spec/foo_spec.rb instead of foo_spec.rb. Caveat: This will not copy the line number...
...to die for this code: function effectiveDeviceWidth() { var deviceWidth = window.orientation == 0 ? window.screen.width : window.screen.height; // iOS returns available pixels, Android returns pixels / pixel ratio // http://www.quirksmode.org/blog/archives/2012/07/more_about_devi.html if (navigator.userAgent.indexOf('Android') >= 0 && window.devicePixelRatio...
...deviceWidth = deviceWidth / window.devicePixelRatio; } return deviceWidth...
...instance to fill in text. Ensure everything is loaded with patiently do page.execute_script("return isCkeditorLoaded('#{selector}');").should be_true end Example The fill in text snippet for Cucumber:
...I fill in the "([^\"]+)" WYSIWYG editor with:$/ do |selector, html| patiently do page.execute_script("return isCkeditorLoaded('#{selector}');").should be_true end html.gsub!(/\n+/, "") # otherwise: unterminated string literal (Selenium::WebDriver::Error...
...you are using Coffeescript, it is likely to be the culprit. Since Coffeescript always returns the value of the last expression, it may return DOM nodes: # coffeescript scope.focus = -> element.focus()
...scope.focus = function() { return element.focus(); // wheee } If you e.g. use this function like this, the error will be raised:
Solution By adding an explicit return value (e.g. return false), you can...
...Element attribute" To access virtually anything, create a "Custom Javascript" variable. Define a function() { return ...; } that returns whatever you need. You can reference other GTM variables with {{ }}.
...need a specific wrapper for the code. Use a function when: You need to return data from the code. You don't need to specify a resource name.
...use .to_json instead of .iso8601 to use the build-in eq matcher: it 'returns the created at attribute of a user' do get '/users/1' expect(JSON.parse(response.body)['created_at...
Previous versions of Consul exhibited strange behavior when querying a power that returns nil. Consul 0.4.2+ behaves as expected: power.notes # => returns nil power.notes? # => returns false power.notes! # => raises Consul::Powerless
...Note.last) # => returns false power.note!(Note.last) # => raises Consul::Powerless
...seems also to have problems with zeitwerk, since the create statement just didn't return. Pry (binding.pry) worked without problems for me. Note: In case you are using pry-byebug...
...to get to a pagination page that does not exist), the database will not return a record and so you will not get the count. To work around this, I...
The class should cache its results so subsequent calls for the same URLs return the HTML size instantly, without making an additional HTTP request. Write two versions of WebsiteSizer...
...If you don't speak CoffeeScript, take this JavaScript: this.app.decorator('$httpBackend', ['$delegate', function($delegate) { return function() { var headers = arguments[4]; var contentType = (headers != null ? headers['X-Force-Content-Type'] : void...
...if (contentType != null && headers['Content-Type'] == null) { headers['Content-Type'] = contentType; } return $delegate.apply(null, arguments...