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
class ApplicationController < ActionController::Base | |
protect_from_forgery | |
def current_ability | |
@current_ability ||= Spree::Ability.new(current_user) | |
end | |
rescue_from CanCan::AccessDenied do |exception| | |
redirect_to :root, :alert => exception.message | |
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
# create a file in config/initializers, e.g. add_abilities_to_spree.rb, | |
# with the following content: | |
Spree::Ability.register_ability MyAppAbility | |
# create a file under app/models (or lib/) to define your abilities (in | |
# this example I protect only the HostAppCoolPage model): | |
class MyAppAbility | |
include CanCan::Ability |
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
HostApplication::Application.routes.draw do | |
devise_for :user, | |
:class_name => 'Spree::User', | |
:controllers => { :sessions => 'spree/user_sessions', | |
:registrations => 'spree/user_registrations', | |
:passwords => 'spree/user_passwords' }, | |
:skip => [:unlocks, :omniauth_callbacks], | |
:path_names => { :sign_out => 'logout' } | |
# ... | |
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
composed_of :expire_date_minus_one_day, | |
:class_name => 'Date', | |
:mapping => %w(Date to_s), | |
:constructor => Proc.new{ |item| item }, | |
:converter => Proc.new{ |item| item } |
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
<p> | |
<%= f.label :expire_date %> | |
<%= f.date_select :expire_date_minus_one_day %> | |
</p> |
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 expire_date_minus_one_day | |
self.expire_date - 1.day | |
end | |
def expire_date_minus_one_day= date | |
self.expire_date = date + 1.day | |
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
# person.rb | |
validates_presence_of :address | |
# blueprints.rb | |
Person.blueprint do | |
name { "John" } | |
surname { "Doe" } | |
address { Address.make } |
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
AREL (0.5ms) INSERT INTO "addresses" ("country", "planet", "created_at", | |
"updated_at") VALUES ('Italy', 'Earth', '2011-06-18 16:45:00.268423', | |
'2011-06-18 16:45:00.268423') |
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
# person.rb | |
validates_presence_of :address | |
# person_factory.rb | |
Factory.define :person do |p| | |
p.name 'John' | |
p.surname 'Doe' | |
p.association :address |
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
ActiveRecord::Base.connection.increment_open_transactions | |
ActiveRecord::Base.connection.begin_db_transaction | |
at_exit do | |
ActiveRecord::Base.connection.rollback_db_transaction | |
ActiveRecord::Base.connection.decrement_open_transactions | |
end |