Skip to content

Instantly share code, notes, and snippets.

@rafaelcgo
Created November 8, 2011 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaelcgo/1348434 to your computer and use it in GitHub Desktop.
Save rafaelcgo/1348434 to your computer and use it in GitHub Desktop.
Gist for Rails Admin #821
=> Booting WEBrick
=> Rails 3.1.0 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/activerecord-3.1.0/lib/active_record/base.rb:1082:in `method_missing': undefined local variable or method `acts_as_messageable' for #<Class:0x108d1d428> (NameError)
from /Users/rafaeloliveira/Development/Rails/mural/hollow/app/models/user.rb:22
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:456:in `load'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:456:in `load_file'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:640:in `new_constants_in'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:455:in `load_file'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:342:in `require_or_load'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:489:in `load_missing_constant'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:181:in `const_missing'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:179:in `each'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:179:in `const_missing'
from /Users/rafaeloliveira/Development/Rails/mural/hollow/config/initializers/rails_admin.rb:683
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/bundler/gems/rails_admin-a2380931e624/lib/rails_admin.rb:47:in `call'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/bundler/gems/rails_admin-a2380931e624/lib/rails_admin.rb:47:in `config'
from /Users/rafaeloliveira/Development/Rails/mural/hollow/config/initializers/rails_admin.rb:12
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:234:in `load'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:234:in `load'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `load_dependency'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:640:in `new_constants_in'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `load_dependency'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:234:in `load'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/railties-3.1.0/lib/rails/engine.rb:555
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/railties-3.1.0/lib/rails/engine.rb:554:in `each'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/railties-3.1.0/lib/rails/engine.rb:554
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/railties-3.1.0/lib/rails/initializable.rb:25:in `instance_exec'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/railties-3.1.0/lib/rails/initializable.rb:25:in `run'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/railties-3.1.0/lib/rails/initializable.rb:50:in `run_initializers'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/railties-3.1.0/lib/rails/initializable.rb:49:in `each'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/railties-3.1.0/lib/rails/initializable.rb:49:in `run_initializers'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/railties-3.1.0/lib/rails/application.rb:92:in `initialize!'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/railties-3.1.0/lib/rails/railtie/configurable.rb:30:in `send'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/railties-3.1.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/rafaeloliveira/Development/Rails/mural/hollow/config/environment.rb:5
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `load_dependency'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:640:in `new_constants_in'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `load_dependency'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'
from /Users/rafaeloliveira/Development/Rails/mural/hollow/config.ru:4
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/rack-1.3.5/lib/rack/builder.rb:51:in `instance_eval'
from /Users/rafaeloliveira/.rvm/gems/ruby-1.8.7-p352@rails310/gems/rack-1.3.5/lib/rack/builder.rb:51:in `initialize'
from /Users/rafaeloliveira/Development/Rails/mural/hollow/config.ru:1:in `new'
from /Users/rafaeloliveira/Development/Rails/mural/hollow/config.ru:1
# RailsAdmin config file. Generated on October 17, 2011 22:03
# See github.com/sferik/rails_admin for more informations
RailsAdmin.config do |config|
config.current_user_method { current_user } # auto-generated
config.main_app_name { ['Mural2', 'Admin'] } # auto-generated
# ==> Authorization
# Use cancan https://github.com/ryanb/cancan for authorization:
config.authorize_with :cancan
# ==> Your models configuration, to help you get started!
config.model Company do
# Found associations:
include_all_fields
exclude_fields :benefits, :candidate_companies, :candidates
# Found columns:
field :logo, :string do
read_only true
formatted_value do
bindings[:view].tag(:img, { :src => bindings[:object].logo, :width => "60px", :height => "auto" }) << value
end
end
# Sections:
edit do
exclude_fields :opportunities, :created_at, :updated_at
field :name do
help 'helptext'
end
end
create do
exclude_fields :company_benefits, :offices
end
end
config.model CompanyBenefit do
# Found associations:
field :benefit, :belongs_to_association
field :company, :belongs_to_association
# Found columns:
field :id, :integer
field :title, :string
field :description, :text
field :value, :float
field :created_at, :datetime
field :updated_at, :datetime
# Sections:
edit do
fields :created_at, :updated_at do
visible false
end
end
end
config.model Office do
object_label_method do
:office_label_method
end
end
config.model Opportunity do
include_all_fields
# Found associations:
exclude_fields :candidates, :cv_opportunities, :comments, :benefits, :tags, :base_tags, :skill_taggings, :skill, :tag_taggings, :taggings
# Found columns:
exclude_fields :company_id
# Sections:
edit do
exclude_fields :cvs, :candidate_opportunities
field :kind do
help 'helptext'
end
end
create do
exclude_fields :opportunity_benefits, :opportunity_offices
end
end
config.model OpportunityOffice do
object_label_method do
:opportunityoffice_label_method
end
end
config.model User do
visible true
# # Found associations:
# field :candidate, :has_one_association
# field :company, :has_one_association
# field :receipts, :has_many_association
# field :messages, :has_many_association
# field :notification_restrictions, :has_many_association
# field :comments, :has_many_association
# # Found columns:
# field :id, :integer
# field :email, :string
# field :password, :password
# field :password_confirmation, :password
# field :password_salt, :string # Hidden
# field :reset_password_token, :string # Hidden
# field :created_at, :datetime
# field :updated_at, :datetime
# field :role, :string
# field :reset_password_sent_at, :datetime
# field :remember_created_at, :datetime
# field :sign_in_count, :integer
# field :current_sign_in_at, :datetime
# field :last_sign_in_at, :datetime
# field :current_sign_in_ip, :string
# field :last_sign_in_ip, :string
# # Sections:
# list do; end
# export do; end
# show do; end
# edit do; end
# create do; end
# update do; end
end
def office_label_method
"#{self.company.name}: #{self.city} - #{self.state}"
end
def opportunityoffice_label_method
"#{self.office.company.name}: #{self.office.city} - #{self.office.state}" if self.office
end
end
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :role
before_validation(:on => :create) do
define_role
add_registration_email
end
after_create :create_candidate
has_one :candidate, :dependent => :destroy
has_one :company, :dependent => :destroy
has_many :comments, :dependent => :destroy
has_many :notification_restrictions, :dependent => :destroy
acts_as_messageable
ROLES = %w[admin candidate company]
def role?(role)
self.role.eql? role.to_s
end
def notifications(options = {})
self.mailbox.notifications(options)
end
def has_unread_notifications?
self.mailbox.notifications(:unread => true).size > 0
end
def notifications_count(options = {})
self.mailbox.notifications(options).count
end
# Mailboxer Helper Methods
def name
return self.candidate.name if self.role? :candidate and self.candidate
return self.company.name if self.role? :company and self.company
return self.email
end
def mailboxer_email(object)
NotificationRestriction.notify_all(
self,
object.notification_code,
object.subject,
object.body
)
# Not using Mailboxer NotificationMailer, instead we are using our own
return nil
end
def create_candidate
if self.role.eql? :candidate.to_s
candidate = Candidate.new({:user_id => self.id})
candidate.save
end
end
def define_role
self.role = :candidate.to_s unless self.role
end
def add_registration_email
self.registration_email = self.email
end
validates :registration_email,
:uniqueness => {
:case_sensitive => false,
:message => 'já utilizado' },
:if => Proc.new { self.role?(:candidate) },
:on => :create
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment