Tutorial by Examples: del

Suppose, your users and/or groups have profiles and you want to display address profile fields on a google map. # app/models/profile_fields/address.rb class ProfileFields::Address < ProfileFields::Base # Attributes: # label, e.g. "Work address" # value, e.g. "Willy-Bran...
To display address profile fields as markers on a google map, the address field objects need to be passed as json objects to javascript. Regular database attributes When calling to_json on an ApplicationRecord object, the database attributes are automatically exposed. Given a ProfileFields::Addre...
If you want to create multiple uploads, first thing you might want to do is create new model and set up relations Let's say you want an multiple images for the Product model. Create an new model and make it belongs_to your parent model rails g model ProductPhoto #product.rb has_many :product_p...
“Fat Model, Skinny Controller” refers to how the M and C parts of MVC ideally work together. Namely, any non-response-related logic should go in the model, ideally in a nice, testable method. Meanwhile, the “skinny” controller is simply a nice interface between the view and model. In practice, this...
You can get a Model class from a Controller name this way (context is Controller class): class MyModelController < ActionController::Base # Returns corresponding model class for this controller # @return [ActiveRecord::Base] def corresponding_model_class # ... add some validation...
Testing your Active Record models through your command line interface is simple. Navigate to the app directory in your terminal and type in rails console to start the Rails console. From here, you can run active record methods on your database. For example, if you had a database schema with a User...
First it is important to understand that the Core Data Model is the *.xcdatamodeld file. You will notice you have not entities. You will have to create one yourself. At the bottom of Xcode you will notice a button that says "Add Entity" click it and you will have a new entity in the ...
Relationships are relationship between entities that can be one-to-one or one-to-many. Creating a relationship is not needed to use Core Data.
Circle To create a circle, define an element with an equal width and height (a square) and then set the border-radius property of this element to 50%. HTML <div class="circle"></div> CSS .circle { width: 50px; height: 50px; background: rgb(246, 156, 85); ...
To create a human-readable presentation of a model object you need to implement Model.__str__() method (or Model.__unicode__() on python2). This method will be called whenever you call str() on a instance of your model (including, for instance, when the model is used in a template). Here's an exampl...
CREATE TRIGGER BooksDeleteTrigger ON MyBooksDB.Books AFTER DELETE AS INSERT INTO BooksRecycleBin SELECT * FROM deleted; GO
Let's say you have a User model class User < ActiveRecord::Base end Now to update the first_name and last_name of a user with id = 1, you can write the following code. user = User.find(1) user.update(first_name: 'Kashif', last_name: 'Liaqat') Calling update will attempt to update the gi...
Create a model (lets call it User) by running: $ rails g model User which will generate the file app/models/user.rb: class User include Mongoid::Document end This is all you need to have a model (albeit nothing but an id field). Unlike ActiveRecord, there is no migration files. All the...
globalize gem is a great solution to add translations to your ActiveRecord models. You can install it adding this to your Gemfile: gem 'globalize', '~> 5.0.0' If you're using Rails 5 you will also need to add activemodel-serializers-xml gem 'activemodel-serializers-xml' Model translations...
DELETE FROM `myTable` WHERE `someColumn` = 'something' The WHERE clause is optional but without it all rows are deleted.
Docker volumes are not automatically removed when a container is stopped. To remove associated volumes when you stop a container: docker rm -v <container id or name> If the -v flag is not specified, the volume remains on-disk as a 'dangling volume'. To delete all dangling volumes: docker ...
ng-model-options allows to change the default behavior of ng-model, this directive allows to register events that will fire when the ng-model is updated and to attach a debounce effect. This directive accepts an expression that will evaluate to a definition object or a reference to a scope value. ...
WITH cte AS ( SELECT ProjectID, ROW_NUMBER() OVER (PARTITION BY ProjectID ORDER BY InsertDate DESC) AS rn FROM ProjectNotes ) DELETE FROM cte WHERE rn > 1;
Realm models must extend the RealmObject base class, they define the schema of the underlying database. Supported field types are boolean, byte, short, int, long, float, double, String, Date, byte[], links to other RealmObjects, and RealmList<T extends RealmModel>. public class Person extend...
A way to use confirm() is when some UI action does some destructive changes to the page and is better accompanied by a notification and a user confirmation - like i.e. before deleting a post message: <div id="post-102"> <p>I like Confirm modals.</p> <a data-dele...

Page 7 of 23