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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> |
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
# Build multiple objects | |
# Association is Client has many projects | |
client = Client.new first_name: "Bob" | |
# Add more projects | |
client.build [{ name: "Project1"}, { name: "Project2" }] | |
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 'devise/strategies/authenticatable' | |
module SubdomainAuthenticatable | |
# Default strategy for signing in a user, based on his email and password in the database. | |
class CustomStrategy < Devise::Strategies::Authenticatable | |
def authenticate! | |
resource = valid_password? && mapping.to.joins(:company).where(authentication_hash.merge({:companies => {:subdomain => "test"}})).first | |
return fail(:not_found_in_database) unless resource | |
if validate(resource){ resource.valid_password?(password) } |
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
def destroy | |
@object.destroy | |
respond_to do |format| | |
format.html { | |
flash[:notice] = "Deleted object." | |
redirect_to(objects_path) | |
} | |
format.xml { head :ok } | |
format.json { head :ok } |
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
@object = object.new(params[:object]) | |
respond_with(@object) do |format| | |
if @object.save | |
format.html { | |
flash[:notice] = "Created a new object successfully." | |
redirect_to objects_path | |
} | |
format.json { render :json => object.find(@object).to_json, :status => :created, :location => @object } | |
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
# Takes the slug, downcases it and replaces non-word characters with a -. | |
# Feel free to override this method if you'd like different slug formatting. | |
def normalize_slug_url | |
return if self.name.blank? | |
s = ActiveSupport::Multibyte.proxy_class.new(self.name).normalize(:kc) | |
s.downcase! | |
s.strip! | |
s.gsub!(/[^a-z0-9\s-]/, '') # Remove non-word characters | |
s.gsub!(/\s+/, '-') # Convert whitespaces to dashes | |
s.gsub!(/-\z/, '') # Remove trailing dashes |
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
def convert_date(date_string) | |
if date_string.present? | |
date = Time.parse(date_string.to_s) | |
date.strftime("%b %d, %Y") | |
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
/** | |
* The first commented line is your dabblet’s title | |
*/ | |
/*background: #f06; | |
background: linear-gradient(45deg, #f06, yellow); | |
min-height:100%;*/ | |
div { | |
background-color: red; float: left; width: 100px; | |
-webkit-animation-duration: 3s; |
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
/** | |
* The first commented line is your dabblet’s title | |
*/ | |
background: #f06; | |
background: linear-gradient(45deg, #f06, yellow); | |
min-height:100%; |
NewerOlder