code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
# This migration comes from spree (originally 20110314192118)
class RemoveTrailingSlashesInTaxonPermalinks < ActiveRecord::Migration
def up
taxons = select_all "SELECT * FROM taxons"
taxons.each do |taxon|
if taxon['permalink'] && taxon['permalink'][-1..-1] == '/'
execute "UPDATE taxons SET perm... | Ruby |
# This migration comes from spree_api (originally 20120530054546)
class RenameApiKeyToSpreeApiKey < ActiveRecord::Migration
def change
unless defined?(User)
rename_column :spree_users, :api_key, :spree_api_key
end
end
end
| Ruby |
# This migration comes from spree (originally 20100427121301)
class AddDisplayToPaymentMethods < ActiveRecord::Migration
def change
add_column :payment_methods, :display, :string, :default => nil
end
end
| Ruby |
# This migration comes from spree (originally 20100125145351)
class AddTestModeToBillingIntegration < ActiveRecord::Migration
def change
add_column :billing_integrations, :test_mode, :boolean, :default => true
add_column :billing_integrations, :server, :string, :default => 'test'
end
end
| Ruby |
# This migration comes from spree (originally 20100812162326)
class PaymentsStateAndAssignedToOrderOnly < ActiveRecord::Migration
def up
# TODO: migrate existing payments
rename_column :payments, :payable_id, :order_id
remove_column :payments, :payable_type
add_column :payments, :state, :string
end
... | Ruby |
# This migration comes from spree (originally 20101026184714)
class Transaction < ActiveRecord::Base; end
class CreditcardTxn < Transaction; end
class MigrateTransactionsToPaymentState < ActiveRecord::Migration
AUTHORIZED=1
COMPLETED=2
PURCHASED=3
VOIDED = 4
CREDITED =5
PAYMENT_COMPLETE = 'completed'
P... | Ruby |
# This migration comes from spree (originally 20100929151905)
class RenameFrozenToLocked < ActiveRecord::Migration
def change
rename_column :adjustments, :frozen, :locked
end
end
| Ruby |
# This migration comes from spree (originally 20101026184855)
class RemoveShippedState < ActiveRecord::Migration
def up
execute "UPDATE orders SET state = 'complete' WHERE state = 'shipped'"
shipments = select_all "SELECT shipments.id FROM shipments WHERE order_id IN (SELECT orders.id FROM orders WHERE orders... | Ruby |
# This migration comes from spree (originally 20111215032408)
class AddCompanyToAddresses < ActiveRecord::Migration
def change
add_column :spree_addresses, :company, :string
end
end
| Ruby |
# This migration comes from spree_promo (originally 20100501084722)
class MatchPolicyForPromotions < ActiveRecord::Migration
def change
add_column :promotions, :match_policy, :string, :default => 'all'
end
end
| Ruby |
# This migration comes from spree (originally 20120315064358)
class MigrateImagesFromProductsToVariants < ActiveRecord::Migration
def up
images = select_all("SELECT spree_assets.* FROM spree_assets
WHERE spree_assets.type = 'Spree::Image'
AND spree_assets.viewable... | Ruby |
# This migration comes from spree (originally 20100112151511)
class CreateReturnAuthorizations < ActiveRecord::Migration
def change
create_table :return_authorizations do |t|
t.string :number, :state
t.decimal :amount, :precision => 8, :scale => 2, :default => 0.0, :null => false
t.references :o... | Ruby |
# This migration comes from spree (originally 20100811163637)
class AddGuestFlag < ActiveRecord::Migration
def change
unless defined?(User)
add_column :users, :guest, :boolean
end
end
end
| Ruby |
# This migration comes from spree (originally 20091209153045)
class StateForShipments < ActiveRecord::Migration
def change
add_column :shipments, :state, :string
end
end
| Ruby |
# This migration comes from spree (originally 20120604203654)
class RemoveCreditTotalFromOrders < ActiveRecord::Migration
def change
remove_column :spree_orders, :credit_total
end
end
| Ruby |
# This migration comes from spree (originally 20100528185820)
class AddIndexOnUsersPersistenceToken < ActiveRecord::Migration
def change
unless defined?(User)
add_index :users, :persistence_token
end
end
end
| Ruby |
# This migration comes from spree (originally 20100121160010)
class CreditcardIdForCreditcardTxns < ActiveRecord::Migration
def change
add_column :creditcard_txns, :creditcard_id, :integer
end
end
| Ruby |
# This migration comes from spree (originally 20120203001428)
class RenameStateEventsToStateChanges < ActiveRecord::Migration
def up
rename_table :spree_state_events, :spree_state_changes
end
def down
rename_table :spree_state_changes, :spree_state_events
end
end
| Ruby |
# This migration comes from spree (originally 20101028151745)
class RemoveNumberAndCvvFromCredicard < ActiveRecord::Migration
def up
remove_column :creditcards, :number
remove_column :creditcards, :verification_value
end
def down
add_column :creditcards, :verification_value, :text
add_column :cre... | Ruby |
# This migration comes from spree (originally 20101026184959)
class GenerateAnonymousUsers < ActiveRecord::Migration
def up
Spree::LegacyUser.table_name = 'users'
Spree::Order.table_name = 'orders'
Spree::LegacyUser.reset_column_information
Spree::Order.where(:user_id => nil).each do |order|
us... | Ruby |
# This migration comes from spree (originally 20091008091614)
class MoveToConfigurableGateways < ActiveRecord::Migration
def up
drop_table :gateways
drop_table :gateway_options
drop_table :gateway_option_values
drop_table :gateway_configurations
create_table :gateways, :force => true do |t|
... | Ruby |
# This migration comes from spree (originally 20100105090147)
class AddCostPrice < ActiveRecord::Migration
def change
add_column :variants, :cost_price, :decimal, :null => true, :default => nil, :precision => 8, :scale => 2
end
end
| Ruby |
# This migration comes from spree (originally 20120105195817)
class AddMatchRulesToShippingMethods < ActiveRecord::Migration
def change
add_column :spree_shipping_methods, :match_none, :boolean
add_column :spree_shipping_methods, :match_all, :boolean
add_column :spree_shipping_methods, :match_one, :boolea... | Ruby |
# This migration comes from spree_auth (originally 20101026184949)
class CreateUsers < ActiveRecord::Migration
def up
unless table_exists?("spree_users")
create_table "spree_users", :force => true do |t|
t.string "crypted_password", :limit => 128
t.string "salt", ... | Ruby |
# This migration comes from spree (originally 20120604030249)
class AddDeletedAtToSpreeShippingMethods < ActiveRecord::Migration
def change
add_column :spree_shipping_methods, :deleted_at, :datetime
end
end
| Ruby |
# This migration comes from spree (originally 20120507232704)
class IncreaseScaleOfTaxRateAmount < ActiveRecord::Migration
def up
change_column :spree_tax_rates, :amount, :decimal, { :scale => 5, :precision => 8 }
end
def down
change_column :spree_tax_rates, :amount, :decimal, { :scale => 4, :precision =... | Ruby |
# This migration comes from spree (originally 20100819170125)
class RefactorAdjustments < ActiveRecord::Migration
def up
change_table :adjustments do |t|
t.boolean :mandatory
t.boolean :frozen
t.rename :adjustment_source_id, :source_id
t.rename :adjustment_source_type, :source_type
t... | Ruby |
# This migration comes from spree_promo (originally 20120119024708)
class CreateSpreePendingPromotions < ActiveRecord::Migration
def change
create_table :spree_pending_promotions do |t|
t.references :user
t.references :promotion
end
add_index :spree_pending_promotions, :user_id
add_index ... | Ruby |
# This migration comes from spree (originally 20091209202200)
class MakeStateEventsPolymorphic < ActiveRecord::Migration
def up
rename_column :state_events, :order_id, :stateful_id
add_column :state_events, :stateful_type, :string
execute "UPDATE state_events SET stateful_type = 'Order'"
end
def down... | Ruby |
# This migration comes from spree (originally 20100506180619)
class AddIconToTaxons < ActiveRecord::Migration
def up
# skip this migration if the attribute already exists because of advanced taxon extension
return if column_exists?(:taxons, :icon_file_name)
add_column :taxons, :icon_file_name, :string
... | Ruby |
# This migration comes from spree_auth (originally 20120605211305)
class MakeUsersEmailIndexUnique < ActiveRecord::Migration
def up
add_index "spree_users", ["email"], :name => "email_idx_unique", :unique => true
end
def down
remove_index "spree_users", :name => "email_idx_unique"
end
end
| Ruby |
# This migration comes from spree (originally 20120530012000)
class RenameCreditcardsToCreditCards < ActiveRecord::Migration
def change
rename_table :spree_creditcards, :spree_credit_cards
execute("UPDATE spree_payments SET source_type = 'Spree::CreditCard' WHERE source_type = 'Spree::Creditcard'")
end
d... | Ruby |
# This migration comes from spree_api (originally 20100107141738)
class AddApiKeyToSpreeUsers < ActiveRecord::Migration
def change
unless defined?(User)
add_column :spree_users, :api_key, :string, :limit => 40
end
end
end
| Ruby |
# This migration comes from spree (originally 20091104151730)
class AddSomeIndexes < ActiveRecord::Migration
def change
add_index :taxons, :permalink
add_index :taxons, :parent_id
add_index :taxons, :taxonomy_id
add_index :assets, :viewable_id
add_index :assets, [:viewable_type, :type]
add_ind... | Ruby |
# This migration comes from spree (originally 20100113203104)
class CreateTrackers < ActiveRecord::Migration
def change
create_table :trackers do |t|
t.string :environment, :analytics_id
t.boolean :active, :default => true
t.timestamps
end
end
end
| Ruby |
# This migration comes from spree_promo (originally 20120119024707)
require 'spree/core/preference_rescue'
class NamespacePromoTables < ActiveRecord::Migration
def concat(str1, str2)
dbtype = Rails.configuration.database_configuration[Rails.env]['adapter'].to_sym
case dbtype
when :mysql, :mysql2
... | Ruby |
# This migration comes from spree (originally 20091015153048)
class AddOpenidFieldToUsers < ActiveRecord::Migration
def up
unless defined?(User)
add_column :users, :openid_identifier, :string
add_index :users, :openid_identifier
change_column :users, :login, :string, :default => nil, :null => t... | Ruby |
# This migration comes from spree (originally 20091213222815)
class CreditcardLastFourDigits < ActiveRecord::Migration
def up
rename_column :creditcards, :display_number, :last_digits
creditcards = select_all "SELECT * FROM creditcards"
creditcards.each do |card|
execute "UPDATE creditcards SET las... | Ruby |
# This migration comes from spree (originally 20101026184916)
class PreventNilPaymentTotal < ActiveRecord::Migration
def up
execute "UPDATE orders SET payment_total = 0.0 WHERE payment_total IS NULL"
end
def down
end
end
| Ruby |
# This migration comes from spree (originally 20100213103131)
class ChangePaymentsPaymentMethodToBelongsTo < ActiveRecord::Migration
def up
remove_column :payments, :payment_method
add_column :payments, :payment_method_id, :integer
end
def down
add_column :payments, :payment_method, :string
... | Ruby |
# This migration comes from spree (originally 20101026184808)
class MigrateCheckoutToOrders < ActiveRecord::Migration
def up
orders = select_all "SELECT * FROM orders"
orders.each do |order|
checkout = update_order(order)
execute "DELETE FROM checkouts WHERE id = #{checkout['id']}" if checkout
... | Ruby |
# This migration comes from spree (originally 20110418151136)
class EligibleForAdjustments < ActiveRecord::Migration
def change
add_column :adjustments, :eligible, :boolean, :default => true
end
end
| Ruby |
# This migration comes from spree (originally 20100903203949)
class EmailForOrders < ActiveRecord::Migration
def change
add_column :orders, :email, :string
end
end
| Ruby |
# This migration comes from spree (originally 20091211203813)
class ShipAddressIdForCheckouts < ActiveRecord::Migration
def change
add_column :checkouts, :ship_address_id, :integer
end
end
| Ruby |
# This migration comes from spree (originally 20100901171814)
class ChangeGuestFlagToAnonymous < ActiveRecord::Migration
def change
unless defined?(User)
rename_column :users, :guest, :anonymous
end
end
end
| Ruby |
# This migration comes from spree (originally 20090823005402)
class SpreeZeroNineZero < ActiveRecord::Migration
# This is a legacy migration consolidating all of the database changes needed as of Spree 0.9.0
# (See http://railsdog.lighthouseapp.com/projects/31096-spree/tickets/772)
def change
create_table :a... | Ruby |
# This migration comes from spree (originally 20100816212146)
class ShippingMethodIdForOrders < ActiveRecord::Migration
def change
add_column :orders, :shipping_method_id, :integer
end
end
| Ruby |
# This migration comes from spree (originally 20100605152042)
class AddDefaultToTaxCategories < ActiveRecord::Migration
def change
add_column :tax_categories, :is_default, :boolean, :default => false
end
end
| Ruby |
# This migration comes from spree (originally 20120203153759)
class AddDeletedAtToTaxCategory < ActiveRecord::Migration
def change
add_column :spree_tax_categories, :deleted_at, :datetime
end
end
| Ruby |
# This migration comes from spree (originally 20100506185838)
class AddDescriptionToTaxons < ActiveRecord::Migration
def up
# skip this migration if the attribute already exists because of advanced taxon extension
return if column_exists?(:taxons, :description)
add_column :taxons, :description, :t... | Ruby |
# This migration comes from spree (originally 20111219203242)
class RenameIncPriceAttribute < ActiveRecord::Migration
def change
rename_column :spree_tax_rates, :inc_tax, :included_in_price
end
end
| Ruby |
# This migration comes from spree (originally 20100624123336)
class RenamePaymentMethodDisplay < ActiveRecord::Migration
def change
rename_column :payment_methods, :display, :display_on
end
end
| Ruby |
# This migration comes from spree (originally 20100209025806)
class CreatePaymentMethods < ActiveRecord::Migration
def change
create_table :payment_methods do |t|
t.string :type, :name
t.text :description
t.boolean :active, :default => true
t.string :environment, :default => 'development'
... | Ruby |
# This migration comes from spree_promo (originally 20120119024721)
# LandingPage used to support static pages, we've moved to a static
# event. This adds path to promotions then migrates the old LandingPage rules
class ContentVisitedEvent < ActiveRecord::Migration
# Removed Class for Migrations
class Spree::Promo... | Ruby |
# This migration comes from spree (originally 20100817152723)
class AddShipmentAndPaymentState < ActiveRecord::Migration
def change
add_column :orders, :shipment_state, :string
add_column :orders, :payment_state, :string
end
end | Ruby |
# This migration comes from spree (originally 20100111205525)
class CimFieldsForCreditcards < ActiveRecord::Migration
def change
add_column :creditcards, :gateway_customer_profile_id, :string
add_column :creditcards, :gateway_payment_profile_id, :string
end
end
| Ruby |
# This migration comes from spree_promo (originally 20101026184833)
class MigrateAdjustments < ActiveRecord::Migration
def up
execute "UPDATE spree_adjustments SET amount = 0.0 WHERE amount IS NULL"
execute "UPDATE spree_adjustments SET mandatory = #{quoted_true} WHERE locked = #{quoted_true}"
end
def do... | Ruby |
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel... | Ruby |
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run Brands4less::Application
| Ruby |
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
#
# Note: You'll currently still have to declare fixtures explicitly in integrati... | Ruby |
class PhenomCompiler
end
puts "hello" | Ruby |
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
def get1()
doc = open("2001_u8.html") { |f| Hpricot(f) }
(doc/"a").each do |link|
if link['href'] =~ /00.shtml$/
puts "http://www.dangdang.com" + link['href']
end
end
end
def get2()
Dir.glob('01*.shtml').each do |fn|
# puts fn
found... | Ruby |
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
def get_book_url(path)
book_types = {}
Dir.glob("#{path}/01*.shtml").each do |fn|
# puts fn
fn =~ /01\.(\d+?)\./
type_id = $1
doc = Hpricot(open(fn))
doc.search("a").each do |link|
href = link['href']... | Ruby |
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
SITE_URL = "http://www.dangdang.com"
def get_all_txt_pages(txt_urls)
txt_urls.each_key do |txturl|
url = SITE_URL + txturl
max = 0
maxurl = ""
fn_base = txturl.sub(".shtml", "")
# use local file as cac... | Ruby |
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
def get_relatives(list_file)
rels = {}
total_books = 0
cnt = 1
File.open(list_file).each_line do |file|
file.chomp!
file =~ /(\d+)\D*$/
book_id = $1
# print "%s\t'%s'\n" % [file, book_id]
url = "http://pr... | Ruby |
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
def get_book_url(path)
book_types = {}
Dir.glob("#{path}/01*.shtml").each do |fn|
# puts fn
fn =~ /01\.(\d+?)\./
type_id = $1
doc = Hpricot(open(fn))
doc.search("a").each do |link|
href = link['href']... | Ruby |
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
SITE_URL = "http://www.dangdang.com"
def get_all_txt_pages(txt_urls)
txt_urls.each_key do |txturl|
url = SITE_URL + txturl
max = 0
maxurl = ""
fn_base = txturl.sub(".shtml", "")
# use local file as cac... | Ruby |
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
def get_relatives(list_file)
rels = {}
total_books = 0
cnt = 1
File.open(list_file).each_line do |file|
file.chomp!
file =~ /(\d+)\D*$/
book_id = $1
# print "%s\t'%s'\n" % [file, book_id]
url = "http://pr... | Ruby |
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
def get1()
doc = open("2001_u8.html") { |f| Hpricot(f) }
(doc/"a").each do |link|
if link['href'] =~ /00.shtml$/
puts "http://www.dangdang.com" + link['href']
end
end
end
def get2()
Dir.glob('01*.shtml').each do |fn|
# puts fn
found... | Ruby |
#!/usr/bin/env ruby
# encoding: utf-8
project = 'battery-indicator'
user = `cat ~/.netrc | awk '{print $4;}'`.strip
pass = `cat ~/.netrc | awk '{print $6;}'`.strip
version = `grep "android:versionName=" AndroidManifest.xml`.split('"')[1]
apk_location = "BatteryIndicatorPro-#{version}.apk"
system("cp bin/*-release.ap... | Ruby |
#!/usr/bin/env ruby
require 'net/http'
require 'uri'
LANGS_URI = 'http://ath.darshancomputing.com/bi/langs/'
langs = Net::HTTP.get(URI.parse(LANGS_URI)).split()
langs.each do |lang|
if lang.length == 2
dir = 'res/values-' << lang
else
dir = 'res/values-' << lang[0,2] << '-r' << lang[2,2]
end
if ! D... | Ruby |
#!/usr/bin/env ruby
# encoding: utf-8
require 'nokogiri'
# read in convert.xml to see which how to convert the string-arrays
# for each strings.xml in res/values res/values-?? res/values-??-*
# find the string-arrays that match the ones in convert.xml and for each
# remove opening and closing string-array tag
#... | Ruby |
require 'RMagick'
class NumberImageGenerator
@@IMAGE_DIR = 'numbers-hdpi/'
def generate(text, fs=18)
#filename = "b" + sprintf("%03d", text) + ".png";
filename = "" + sprintf("%03d", text) + ".png";
font_size = fs;
height = 35;
width = 35;
image = Magick::Image.new(width, height) {self.ba... | Ruby |
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel... | Ruby |
class CreateVotes < ActiveRecord::Migration
def change
create_table :votes do |t|
t.integer :score
t.references :post
end
end
end
| Ruby |
class CreateRoles < ActiveRecord::Migration
def change
create_table :roles do |t|
t.string :name
end
end
end
| Ruby |
class DeviseCreateUsers < ActiveRecord::Migration
def change
create_table(:users) do |t|
## Database authenticatable
t.string :email, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""
## Recoverable
t.string :reset_password_to... | Ruby |
class AddReferneces < ActiveRecord::Migration
def change
change_table :users_votes do |f|
f.references :user
f.references :vote
end
end
end
| Ruby |
class CreateUsersVotes < ActiveRecord::Migration
def change
create_table :users_votes do |t|
t.timestamps
end
end
end
| Ruby |
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.string :title
t.text :content
t.references :user
t.timestamps
end
add_index :posts, :user_id
end
end
| Ruby |
class CreateUsersRoles < ActiveRecord::Migration
def change
create_table :users_roles do |t|
t.references :user
t.references :role
t.timestamps
end
end
end
| Ruby |
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
#
# Note: You'll currently still have to declare fixtures explicitly in integrati... | Ruby |
source 'https://rubygems.org'
gem 'rails', '3.2.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3... | Ruby |
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'
| Ruby |
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require "cancan/matchers"
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/... | Ruby |
# Read about factories at http://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :vote do
score 0
end
end
| Ruby |
FactoryGirl.define do
factory :role do
name "user"
end
end | Ruby |
FactoryGirl.define do
factory :user do
sequence(:email) {|n| "email#{n}@abc.com" }
password "1234567"
end
end | Ruby |
# Read about factories at http://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :users_vote do
end
end
| Ruby |
FactoryGirl.define do
factory :post do
sequence(:title) {|n| "New Title -- #{n}" }
content "MyText"
user
end
end
| Ruby |
module ApplicationHelper
def resource_name
:user
end
def resource
@resource ||= User.new
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end
end
| Ruby |
module PostsHelper
end
| Ruby |
module VoteHelper
end
| Ruby |
class UsersVote < ActiveRecord::Base
belongs_to :user
belongs_to :vote
end | Ruby |
class Post < ActiveRecord::Base
after_create :create_vote
belongs_to :user
has_one :vote, :dependent => :destroy
validates :title, :content, :presence => true
protected
def create_vote
self.vote = Vote.create(:score => 0)
end
end
| Ruby |
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
before_create :create_role
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable... | Ruby |
class Vote < ActiveRecord::Base
belongs_to :post
has_many :users_votes
has_many :users, :through => :users_votes
end
| Ruby |
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new
if user.role? :admin
can :manage, Post
can :clear, Vote
else
can :read, :all
if user.role?(:user)
can :create, Post
can :update, Post do |post|
post.try(:user) == user
... | Ruby |
class Role < ActiveRecord::Base
has_many :users_roles
has_many :users, :through => :users_roles
end
| Ruby |
class UsersRole < ActiveRecord::Base
belongs_to :role
belongs_to :user
end | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.