Skip to content

Instantly share code, notes, and snippets.

View AndyObtiva's full-sized avatar

Andy Maleh AndyObtiva

View GitHub Profile
@AndyObtiva
AndyObtiva / ruby_conditional_that_makes_me_cry.rb
Created May 9, 2011 16:07
Ruby conditional code that makes me cry
extra_attributes.each do |name, value|
case name.to_sym
when :fullname
self.fullname = value
when :email
self.email = value
end
end
@AndyObtiva
AndyObtiva / multi_line_if_value_assignment.rb
Created December 13, 2011 16:41
Non-recommended Ruby multi-line if conditional assignment of value
# Not easy to parse and read.
value = if conditional
# do some work
# do more work
value1
else
# do some work
# do more work
value2
end
@AndyObtiva
AndyObtiva / routes.rb
Last active December 24, 2015 07:49
Ultra Light & Maintainable Wizards - Routes
resources :projects, only: [:create] do
resources :project_parts, only: [:edit, :update]
end
def create
@project = current_user.projects.create
redirect_to edit_project_project_part_path(@project, "basic_info")
end
class ProjectPartsController < ApplicationController
before_filter :authenticate_user!, :authorize_project
STEPS = ['basic_info', 'detail', 'document_content', 'preview']
def edit
if wizard_step_project.editable?
if step.present?
render step
else
@AndyObtiva
AndyObtiva / basic_info.rb
Created October 23, 2013 06:39
Project::BasicInfo
class Project::BasicInfo < Project
validates :business_campaign_name, :presence => true, :length => {:maximum => 255}
validates :money_to_raise_min, :presence => true, :numericality => {:greater_than => 0}
validates :money_to_raise_max, :presence => true, :numericality => {:greater_than => 0}
#add validation that money_to_raise_min is greater than 0
validates :deadline, :presence => true
validates :name, :presence => true, :length => {:maximum => 255}
validates :company_name, :presence => true, :length => {:maximum => 255}
validates :position_role, :presence => true, :length => {:maximum => 255}
validates :email, :presence => true, :format => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
@AndyObtiva
AndyObtiva / detail.rb
Last active December 26, 2015 07:09
Project::Detail
class Project::Detail < Project
validates :business_concept_mission, presence: true, length: {maximum: 4000}
validates :goals_essay, presence: true, length: {maximum: 4000}
validates :good_investment_proposition, presence: true, length: {maximum: 4000}
after_update :complete!
private
def complete!
@AndyObtiva
AndyObtiva / project.rb
Created October 23, 2013 06:45
Project model
class Project < ActiveRecord::Base
extend FriendlyId
attr_accessible :business_campaign_name, :money_to_raise_min, :money_to_raise_max, :deadline, :name, :company_name, :position_role, :email, :phone, :business_concept_mission, :goals_essay, :good_investment_proposition, :overview, :embedded_media, :tagline, :city, :state, :number_of_employees,:company_website, :facebook, :linkedin, :twitter, :pinterest, :blog, :industry, :company_image, :money_raised, :featured_category, :passcode, :offering_type, :valuation, :tax_id
friendly_id :business_campaign_name, use: :slugged
has_many :documents, :conditions => {:category => 'document'}
has_many :private_documents, :class_name => "Document", :conditions => { :category => 'private_document' }
has_many :events, dependent: :destroy
<%= form_for @project, :url => project_project_part_path(@project.id, params[:id]), :as => :project} do |f| %>
...
<% end %>
@AndyObtiva
AndyObtiva / 0_reuse_code.js
Created January 23, 2014 17:09
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console