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
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 |
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
one: | |
first_name: Test | |
last_name: Test | |
email_address: [email protected] | |
username: admin | |
password_digest: <%= BCrypt::Password.create('test') %> | |
two: | |
first_name: Test2 | |
last_name: Test2 |
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
group :development do | |
gem 'sqlite3' | |
end | |
group :production do | |
gem 'mysql' | |
end | |
# Use unicorn as the web server | |
gem 'unicorn' |
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
<div class="field"> | |
<%= f.label :created_at, "Published at" %> | |
<div class="datetime"> | |
<%= f.datetime_select :created_at %> | |
</div> | |
</div> |
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
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 |
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
<div class="datetime"> | |
<% if @post.user.nil? %> | |
No author specified | |
<% else %> | |
<%= @post.user.username %> | |
<% end %> | |
</div> |
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
# index and new action in my password resets controller | |
def index | |
if current_user | |
redirect_to account_url | |
else | |
redirect_to '/login' | |
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
# 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 |
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
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 | |
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
<%= | |
link_to_if(@current_user.nil?, "Login", { :controller => "sessions", :action => "new" }) do | |
link_to(@current_user.login, { :controller => "accounts", :action => "show", :id => @current_user }) | |
end | |
%> |
OlderNewer