Skip to content

Instantly share code, notes, and snippets.

View eileencodes's full-sized avatar
👩‍💻

Eileen M. Uchitelle eileencodes

👩‍💻
View GitHub Profile
class Widget < ActiveRecord::Base
# initialized contstant for the validator
VALID_COLORS = %(red white blue)
belongs_to :box
has_many :categorizations
has_many :categories, :through => :categorizations
validates_presence_of :name
validates_length_of :name, :minimum => 3
validates_numericality_of :size
one:
first_name: Test
last_name: Test
email_address: test@gmail.com
username: admin
password_digest: <%= BCrypt::Password.create('test') %>
two:
first_name: Test2
last_name: Test2
@eileencodes
eileencodes / Gemfile
Created January 4, 2012 16:54
Setting up your Gemfile for deployment
group :development do
gem 'sqlite3'
end
group :production do
gem 'mysql'
end
# Use unicorn as the web server
gem 'unicorn'
<div class="field">
<%= f.label :created_at, "Published at" %>
<div class="datetime">
<%= f.datetime_select :created_at %>
</div>
</div>
class Admin::PostsController < Admin::AdminController
#only showing the update method
def update
@post = Post.find(params[:id])
if @post.valid?
add_author_to_post
save_or_remove_post_categorization
end
<div class="datetime">
<% if @post.user.nil? %>
No author specified
<% else %>
<%= @post.user.username %>
<% end %>
</div>
@eileencodes
eileencodes / password_resets_controller.rb
Created January 25, 2012 22:18
class PasswordResetsController < ApplicationController
# index and new action in my password resets controller
def index
if current_user
redirect_to account_url
else
redirect_to '/login'
end
end
@eileencodes
eileencodes / password_resets_controller.rb
Created January 25, 2012 22:23
class PasswordResetsController < ApplicationController
# create action for generate password token for forgot password
def create
user = User.find_by_email(params[:email])
if user
user.generate_password_reset if user
render :index
else
flash.now.alert = "No such email address was found. Please try again."
render :action => 'new'
end
@eileencodes
eileencodes / password_resets_controller.rb
Created January 25, 2012 22:24
class PasswordResetsController < ApplicationController
def edit
@user = User.find_by_reset_pass_token(params[:id])
if @user.nil?
redirect_to '/login', :alert => 'Password reset does not exist.'
elsif @user.reset_pass_expiration < 2.hours.ago
redirect_to '/login ', :alert => "Password reset has expired."
end
end
@eileencodes
eileencodes / link_to_if_ex.rb
Created March 1, 2012 21:21
Example of link_to_if from Rails API