Skip to content

Instantly share code, notes, and snippets.

@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 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_controller.rb
Created November 20, 2018 07:09
authenticate any of the user model using devise - Rails
def authenticate_any!
if user_signed_in?
true
else
authenticate_account!
end
end
@abhianair
abhianair / controller.rb
Created November 16, 2018 11:08
Enter Subdomain name inside input field and redirect to its domain if the subdomain present.
def proceed
@domain_from_form = params[:search][:q]
@domain_search = User.pluck(:subdomain)
@domain_present = @domain_search.include? @domain_from_form
if @domain_present == true
redirect_to "http://#{@domain_from_form}.lvh.me:3000/accounts/sign_in"
else
redirect_to resub_index_path
end
end
@abhianair
abhianair / confirmation_instruction.html.erb
Created November 12, 2018 04:38
Confirmation mail sent from tenant
<p>Welcome <%= @email.split('@')[0].capitalize %>!</p>
<p>Your Mail is Verified ! You can procees your signing Up By clicking the link below.</p>
<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token, subdomain: Apartment::Tenant.current) %></p>
@abhianair
abhianair / model.rb
Created November 2, 2018 08:23
Adding Input from Multi Select Box and converting to a string a store it in a single column in a database - Rails
def days=(value)
return super value.reject!(&:blank?).join(", ") if value.is_a?(Array)
super
end
@abhianair
abhianair / .erb
Created November 2, 2018 06:55
Multiple Check Box A probable failed code but can be compiled successfully by perfection
<div class="field">
<%= label_tag 'days_monday', 'Monday' %>
<%= check_box_tag 'business_pro[days][]','Monday',checked('pop'), id: 'days_monday' %>
<%= label_tag 'days_tuesday', 'Tuesday' %>
<%= check_box_tag 'business_pro[days][]','Tuesday',checked('pop'), id: 'days_tuesday' %>
<%= label_tag 'days_wednesday', 'Wednesday' %>
<%= check_box_tag 'business_pro[days][]','Wednesday',checked('pop'), id: 'days_wednesday' %>
</div>
@abhianair
abhianair / .rb
Created November 1, 2018 06:24
Creating a Post by a user - Rails
@post.user = current_user
@abhianair
abhianair / .rb
Created November 1, 2018 04:51
Rails console - Maiking a user admin
@user = User.find(id)
@user.admin = true
@user.save!
@abhianair
abhianair / .erb
Created October 30, 2018 04:39
take a username out of user's email in ERB
<%= @posts.user.email.split('@')[0].capitalize %>