This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "google/apis/calendar_v3" | |
require "google/api_client/client_secrets.rb" | |
class TasksController < ApplicationController | |
CALENDAR_ID = 'primary' | |
# GET /tasks/new | |
def new | |
@task = Task.new | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_with(model: @task, local: true) do |form| %> | |
<% if task.errors.any? %> | |
<div id="error_explanation"> | |
<h2><%= pluralize(task.errors.count, "error") %> prohibited this task from being saved:</h2> | |
<ul> | |
<% task.errors.full_messages.each do |message| %> | |
<li><%= massage %></li> | |
<% end %> | |
</ul> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateTasks < ActiveRecord::Migration[5.2] | |
def change | |
create_table :tasks do |t| | |
t.string :title | |
t.string :description | |
t.datetime :start_date | |
t.datetime :end_date | |
t.string :event | |
t.string :members | |
t.references :user, foreign_key: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AddColumnsToUsers < ActiveRecord::Migration[5.2] | |
def change | |
add_column :users, :name, :string | |
add_column :users, :access_token, :string | |
add_column :users, :expires_at, :datetime | |
add_column :users, :refresh_token, :string | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ApplicationRecord | |
# Include default devise modules. Others available are: | |
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable | |
devise :omniauthable, :omniauth_providers => [:google_oauth2] | |
has_many :tasks | |
def self.from_omniauth(access_token) | |
data = access_token.info | |
user = User.where(:email => data["email"]).first |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController | |
def google_oauth2 | |
@user = User.from_omniauth(request.env["omniauth.auth"]) | |
if @user.persisted? | |
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google" | |
auth = request.env["omniauth.auth"] | |
@user.access_token = auth.credentials.token | |
@user.expires_at = auth.credentials.expires_at | |
@user.refresh_token = auth.credentials.refresh_token | |
@user.save! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Msg91MessageService | |
def send_sms(to_number, message) | |
require 'msg91ruby' | |
begin | |
api = Msg91ruby::API.new(ENV['MSG91_AUTH_KEY'], ENV['MSG91_SENDER_ID']) | |
api.send(to_number, message, 4) | |
rescue => e | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2.2.2 :015 > array = Array.new | |
#=> [] | |
2.2.2 :016 > array = Array.new(5) | |
#=> [nil, nil, nil, nil, nil] | |
2.2.2 :017 > array = [ '1', '2', '3' ] | |
#=> ["1", "2", "3"] | |
2.2.2 :018 > array = ('1'..'3').to_a | |
#=> ["1", "2", "3"] | |
2.2.2 :019 > array = *('1'..'3') | |
#=> ["1", "2", "3"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.DRY - Dont' Repeat Yourself | |
2.Two spaces, no tabs | |
3.Boolean Tests: don't use "and" and "or", always use "&&" and "||" | |
Comments | |
-------- | |
1.Remove old commented code | |
2."How to" comments - If you add/change any method/variables etc.., always add detailed description in just above line. So, anybody can understand that code. | |
Camels for Classes, Snakes Everywhere Else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.DRY - Dont' Repeat Yourself | |
2.Two spaces, no tabs | |
3.Boolean Tests: don't use "and" and "or", always use "&&" and "||" | |
Comments | |
-------- | |
1.Remove old commented code | |
2."How to" comments - If you add/change any method/variables etc.., always add detailed description in just above line. So, anybody can understand that code. | |
Camels for Classes, Snakes Everywhere Else |
NewerOlder