This file contains 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
import mandrill | |
import socket | |
REMOTE_SERVER = "www.google.com" | |
#checks if there is internet connection | |
def is_connected(): | |
try: | |
# see if we can resolve the host name -- tells us if there is | |
# a DNS listening |
This file contains 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
<?php | |
function enable_svg_upload_if_admin($mimes) { | |
$current_user_roles = wp_get_current_user()->roles; // get roles of current user | |
// check if user is administrator and user is in the admin panel (not in the frontend) | |
if(in_array('administrator', $current_user_roles) && is_admin()) { | |
$mimes['svg'] = 'image/svg+xml'; | |
return $mimes; // if administrator, enable svg upload | |
} |
This file contains 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
# app/models/user.rb | |
class User | |
has_many :email_addresses | |
accepts_nested_attributes_for :email_addresses | |
# ... association definitions and other methods | |
# Define our overrides: |
This file contains 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
# app/views/devise/registrations/new.html.erb | |
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> | |
<%= render "devise/shared/error_messages", resource: resource %> | |
<%= f.fields_for 'email_addresses_attributes[1]' do |e| %> | |
<div class="field"> | |
<%= e.label :email %><br /> | |
<%= e.email_field :email, autofocus: true, autocomplete: "email" %> | |
</div> | |
<% end %> |
This file contains 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
# app/controllers/registrations_controller.rb | |
class RegistrationsController < Devise::RegistrationsController | |
protected | |
def sign_up_params | |
params.require(:user).permit( | |
:name, | |
:password, | |
:password_confirmation, | |
email_addresses: [ |
This file contains 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
# db/migrate/20200804153022_add_primary_to_email_addresses | |
class AddPrimaryToEmailAddresses < ActiveRecord::Migration[6.0] | |
def change | |
add_column :email_addresses, :primary, :boolean, default: false | |
add_index :email_addresses, :primary | |
end | |
end |
This file contains 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
where(conditions.to_h) | |
.includes(:email_addresses) | |
.where(email_addresses: { | |
email: email, | |
primary: true | |
}).first |
This file contains 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
# app/models/user.rb | |
def email | |
email_address = email_addresses.where(primary: true).first | |
return email_address.email if email_address | |
end |
This file contains 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
# app/models/contact.rb | |
class Contact | |
has_one :user | |
has_many :email_addresses | |
accepts_nested_attributes_for :email_addresses | |
end |
This file contains 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
# app/models/user.rb | |
class User | |
belongs_to :contact | |
# This is optional | |
has_many :email_addresses, through: :contact | |
# So we can create the contact association when creating a User | |
accepts_nested_attributes_for :contact | |
after_initialize :add_contact |
OlderNewer