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 CustomJob | |
def before(job) | |
Delayed::Context.set(:handler, job.handler) | |
Delayed::Context.set(:attempt, job.attempts + 1) | |
Delayed::Context.set(:last_error, job.last_error) if job.last_error | |
end | |
def after(job) | |
Delayed::Context.clear |
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
add_index :table, :column, :unique => true | |
remove_index :table, :column |
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
require 'uuidtools' | |
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
<%= form_tag(search_path, :method => "get") do %> | |
<%= label_tag(:q, "Search for:") %> | |
<%= text_field_tag(:q) %> | |
<%= submit_tag("Search") %> | |
<% end %> | |
# from http://guides.rubyonrails.org/form_helpers.html |
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
state_machine do | |
state :email, :exit => lambda {|reg| reg.errors.clear } | |
state :age, :exit => lambda {|reg| reg.errors.clear } | |
state :complete, :enter => :register_user | |
event :next do | |
transitions :from => :email, :to => :age, :guard => :guard_to_age | |
transitions :from => :age, :to => :complete, :guard => :guard_to_complete | |
# do not allow complete => complete | |
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 update | |
@registration = Registration.find(params[:id]) | |
redirect_to users_path(@registration.user_id) and return if @registration.state == 'complete' | |
if @registration.update_attributes(params[:registration]) | |
if @registration.next! | |
if @registration.state == 'complete' | |
#can only reach this block on first completion -- or next will have failed | |
sign_in(:user, @registration.user) | |
redirect_to user_show_path and return |
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 register_user | |
password = User.send(:generate_token, 'encrypted_password').slice(0, 6) | |
user = User.create!(:name => name, :email => email, :age => age, | |
:password => password, :password_confirmation => password) | |
Notifications.signup(user, password).deliver | |
self.user = user | |
self.save! | |
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 require_email | |
errors.add(:email, "Email is required") unless email.present? | |
if email.present? | |
errors.add(:email, "Email is already taken") if email_in_use?(email) | |
end | |
errors.empty? | |
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
namespace :path1 do | |
resources :my_resource | |
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
scope :path1, :as => 'path1' do | |
constraints(SubdomainConstraints) do | |
resources :my_resource | |
end | |
end |