Tutorial by Examples

Add gem to the Gemfile: gem 'devise' Then run the bundle install command. Use command $ rails generate devise:install to generate required configuration file. Set up the default URL options for the Devise mailer in each environment In development environment add this line: config.action_mailer...
Boolean(0) === false Boolean(0) will convert the number 0 into a boolean false. A shorter, but less clear, form: !!0 === false
To convert a string to boolean use Boolean(myString) or the shorter but less clear form !!myString All strings except the empty string (of length zero) are evaluated to true as booleans. Boolean('') === false // is true Boolean("") === false // is true Boolean('0') === fals...
If the values in a container have certain operators already overloaded, std::sort can be used with specialized functors to sort in either ascending or descending order: C++11 #include <vector> #include <algorithm> #include <functional> std::vector<int> v = {5,1,2,4,3};...
If you have created a table with some wrong schema, then the easiest way to change the columns and their properties is change_table. Review the following example: change_table :orders do |t| t.remove :ordered_at # removes column ordered_at t.string :skew_number # adds a new column t.index...
Managed resources are resources that the runtime's garbage collector is aware and under control of. There are many classes available in the BCL, for example, such as a SqlConnection that is a wrapper class for an unmanaged resource. These classes already implement the IDisposable interface -- it's u...
It's important to let finalization ignore managed resources. The finalizer runs on another thread -- it's possible that the managed objects don't exist anymore by the time the finalizer runs. Implementing a protected Dispose(bool) method is a common practice to ensure managed resources do not have t...
You can add a home page route to your app with the root method. # config/routes.rb Rails.application.routes.draw do root "application#index" # equivalent to: # get "/", "application#index" end # app/controllers/application_controller.rb class Applicati...
Iterating over List List<String> names = new ArrayList<>(Arrays.asList("Clementine", "Duran", "Mike")); Java SE 8 names.forEach(System.out::println); If we need parallelism use names.parallelStream().forEach(System.out::println); Java SE 5 fo...
When a controller action is rendered, Rails will attempt to find a matching layout and view based on the name of the controller. Views and layouts are placed in the app/views directory. Given a request to the PeopleController#index action, Rails will search for: the layout called people in app/...
class UsersController < ApplicationController def index hashmap_or_array = [{ name: "foo", email: "[email protected]" }] respond_to do |format| format.html { render html: "Hello World" } format.json { render json: hashmap_or_array } en...
class UsersController < ApplicationController def index respond_to do |format| format.html { render html: "Hello World" } end end end This is a basic controller, with the addition of the following route (in routes.rb): resources :users, only: [:index] Will...
Controllers have access to HTTP parameters (you might know them as ?name=foo in URLs, but Ruby on Rails handle different formats too!) and output different responses based on them. There isn't a way to distinguish between GET and POST parameters, but you shouldn't do that in any case. class UsersCo...
class UsersController < ApplicationController def index respond_to do |format| format.html do render html: "Hello #{ user_params[:name] } user_params[:sentence]" end end end private def user_params if params[:name] == "john&quo...
Assuming the route: resources :users, only: [:index] You can redirect to a different URL using: class UsersController def index redirect_to "http://stackoverflow.com/" end end You can go back to the previous page the user visited using: redirect_to :back Note that i...
Assuming the route: resources :users, only: [:index] And the controller: class UsersController < ApplicationController def index respond_to do |format| format.html { render } end end end The view app/users/index.html.erb will be rendered. If the view is: Hello &lt...
This function runs an AJAX call using GET allowing us to send parameters (object) to a file (string) and launch a callback (function) when the request has been ended. function ajax(file, params, callback) { var url = file + '?'; // loop through object and assemble the url var notFirst ...
resources :photos do member do get 'preview' end collection do get 'dashboard' end end This creates the following routes in addition to default 7 RESTful routes: get '/photos/:id/preview', to: 'photos#preview' get '/photos/dashboards', to: '...
In JavaScript, all numbers are internally represented as floats. This means that simply using your integer as a float is all that must be done to convert it.
To convert a float to an integer, JavaScript provides multiple methods. The floor function returns the first integer less than or equal to the float. Math.floor(5.7); // 5 The ceil function returns the first integer greater than or equal to the float. Math.ceil(5.3); // 6 The round function...

Page 220 of 1336