Skip to content

Instantly share code, notes, and snippets.

@abhianair
abhianair / controller.rb
Created November 23, 2018 05:06
split array
@day = BusinessProfile.where(:user_id => current_user).pluck(:days)
@days = @day.first
@days = @days.split(',')
@abhianair
abhianair / application.js
Last active December 4, 2018 04:34
Update Country code field upon selecting Country field using AJAX
$(document).ready(function(){
$("#id_country_code").change(function(){
var option = $(this).val();
$.ajax({
type: "GET",
url: "/models/get",
data:{
key: option
},
success: function(response){
@abhianair
abhianair / controller.rb
Created December 4, 2018 04:33
To check if a user already have tuple
before_action :check_have, only: [:new]
def check_have
if Profile.where(:user_id=>current_user.id).present?
redirect_to root_path
end
end
@abhianair
abhianair / model.rb
Created December 6, 2018 06:12
Does not need that todo_list exist
class Task < ApplicationRecord
belongs_to :todo_list, optional: true
end
<div><%= t = Time.parse(appointment.time) %>
<%= date = appointment.date %>
<%= d = Date.new(date.year,date.month,date.day) %>
<%= time = DateTime.new(d.year, d.month, d.day, t.hour, t.min, t.sec) %></div>
@abhianair
abhianair / controller.rb
Created December 24, 2018 05:04
Switch all tenants created using apartment automatically and get data accordingly.
@tenant = Apartment.tenant_names
@tenant.each do |name|
Apartment::Tenant.switch(name) do
@email = Account.pluck(:email)
end
end
@abhianair
abhianair / custom_calendar.js
Created April 5, 2019 12:05
Dynamic custom calendar where day cell is text area Using Jquery.
$( document ).on('turbolinks:load', function() {
var deferentMonth = 0;
var prevEl = document.getElementById('ac-prev'), // get the ID of the prev month button
nextEl = document.getElementById('ac-next'), // get the date of the next month button
daysEl = document.getElementById("custom_calndar2");
const months = [
"JANUARY",
"FEBRUARY",
"MARCH",
"APRIL",
@abhianair
abhianair / datapicker.js
Created April 29, 2019 04:50
Disable an array of dates from Datepicker
var array = ["2019-06-01","2019-06-02","2019-06-03"];
$('#inline-datepicker').datepicker({
// minDate: 0,
beforeShowDay: function(date) {
var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [ array.indexOf(string) == -1 ]
}
});
Data.with_schema('schema_name').all
@abhianair
abhianair / export_controller.rb
Last active July 29, 2019 09:27
Rails export to csv multiple table in a same file
def backup
models = ["table1s","table2s","table3s"]
all_data = Hash.new
models.map do |model_name|
table_data = []
model_name = model_name.split("")
model_name.pop
model_name = model_name.join("")
model_name.camelize.constantize.all.map do |data|
table_data.push(data)