Tutorial by Examples: er

In order to have google maps work properly with turbolinks, add the javascript tag directly to the layout header rather than including it in a view. # app/views/layouts/my_layout.html.haml !!! %html{:lang => 'en'} %head - # ... = google_maps_api_script_tag The google_maps_api_s...
Suppose, there is a .google_map div, which will become the map, and which has the address fields to show as markers as data attribute. For example: <!-- http://localhost:3000/profiles/123 --> <div class="google_map" data-address-fields="[ {label: 'Work address', value: ...
Provided an App.GoogleMap coffee script class and the marker information being stored in the data-address-fields attribute of the .google_map div, the map markers can be initialized on the map like this: # app/assets/javascripts/google_maps.js.coffee # ... class App.GoogleMap # ... markers:...
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 need to search an ActiveRecord model for similar values, you might be tempted to use LIKE or ILIKE but this isn't portable between database engines. Similarly, resorting to always downcasing or upcasing can create performance issues. You can use ActiveRecord's underlying Arel matches method...
NotificationCompat.Builder mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.some_small_icon) .setContentTitle("Title") .setContentText("This is a test notification with MAX priority")...
Cloning an object by implementing the Cloneable interface. public class Sheep implements Cloneable { private String name; private int weight; public Sheep(String name, int weight) { this.name = name; this.weight = weight; } @Override public Ob...
Start using File Uploads in Rails is quite simple, first thing you have to do is to choice plugin for managing uploads. The most common onces are Carrierwave and Paperclip. Both are similar in functionality and rich in documentation on Let's have an look on example with simple avatar upload image w...
To generate a new mailer, enter the following command rails generate mailer PostMailer This will generate a blank template file in app/mailers/post_mailer.rb named PostMailer class PostMailer < ApplicationMailer end Two layout files will also be generated for the email view, one for the...
added in GHC 7.8. OverloadedLists, similar to OverloadedStrings, allows list literals to be desugared as follows: [] -- fromListN 0 [] [x] -- fromListN 1 (x : []) [x .. ] -- fromList (enumFrom x) This comes handy when dealing with types such as Set, Vector and Maps. ['0'...
“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...
Given a file file.txt with the following content: line 1 line 2 line 3 You can add a new line after first matching line with the a command. For portable use the a command must be followed immediately by an escaped newline, with the text-to-append on its own line or lines. sed ' /line 2/a\ ...
xml of the Dialog: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="mat...
String filename = "image.png"; String imagePath = getExternalFilesDir() + "/" + filename; Picasso.with(context) .load(new File(imagePath)) .into(imageView);
Add below to your build.gradle out of android tag: // Apply plug-in to app. apply plugin: 'com.google.gms.google-services' Add below helper class to your util package: /** * Created by Andy */ public class GoogleSignInHelper implements GoogleApiClient.OnConnectionFailedListener, ...
Filters are methods that are run "before", "after" or "around" a controller action. They are inherited, so if you set any in your ApplicationController they will be run for every request your application receives. Before Filter Before filters are executed before the c...
Rails provides a lot of generators, for controllers too of course. You can generate a new controller by running this command in your app folder rails generate controller NAME [action action] [options] Note: You can also use rails g alias to invoke rails generate For example, to generate a cont...
You can rescue a RecordNotFound exception with a redirect instead of showing an error page: class ApplicationController < ActionController::Base # your other stuff rescue_from ActiveRecord::RecordNotFound do |exception| redirect_to root_path, 404, alert: I18n.t("errors.record...
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...
In the case of a multi-project gradle build, you may sometimes need to depend on another project in your build. To accomplish this, you'd enter the following in your project's dependencies: dependencies { compile project(':OtherProject') } Where ':OtherProject' is the gradle path for the p...

Page 116 of 417