Skip to content

Instantly share code, notes, and snippets.

View andywenk's full-sized avatar

Andreas Wenk andywenk

View GitHub Profile
@andywenk
andywenk / eventful_exception
Created June 5, 2012 19:44
eventful_exception
: rails s
=> Booting WEBrick
=> Rails 3.2.5 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-06-05 21:37:45] INFO WEBrick 1.3.1
[2012-06-05 21:37:45] INFO ruby 1.8.7 (2012-01-07) [java]
[2012-06-05 21:37:45] INFO WEBrick::HTTPServer#start: pid=45665 port=3000
[2012-06-05 21:39:56] ERROR NoMethodError: undefined method `debug_rjs=' for ActionView::Base:Class
org/jruby/RubyKernel.java:1955:in `send'
@andywenk
andywenk / reek.rake
Created July 7, 2012 21:45
example reek rake task
require 'reek/rake/task'
Reek::Rake::Task.new do |t|
t.source_files = "app/**/*.rb"
t.verbose = true
t.fail_on_error = false
end
namespace :analyzer do
desc "run reek and find code smells"
@andywenk
andywenk / create_active_admin_example.sh
Created August 27, 2012 19:47
create active_admin_example Rails application
rails new active_admin_example
rake db:create
rails g controller products index
rails g model product name:string description:text price:float
rails g model user first_name:string last_name:string
rails g model order user_id:integer
rails g model order_item order_id:integer product_id:integer quantity:integer
rake db:migrate
@andywenk
andywenk / gist:3491715
Created August 27, 2012 19:48
active_admin_example models
class User < ActiveRecord::Base
has_many :orders
attr_accessible :first_name, :last_name
end
class Order < ActiveRecord::Base
belongs_to :user
has_many :order_items
attr_accessible :total, :user_id
end
@andywenk
andywenk / install_active_admin.sh
Created August 27, 2012 19:50
install active_admin
bundle install
rails generate active_admin:install
rake db:migrate
rails s
@andywenk
andywenk / generate_active_admin_resources.sh
Created August 27, 2012 19:51
generate active_admin ressources
rails generate active_admin:resource user
rails generate active_admin:resource product
rails generate active_admin:resource order
rails generate active_admin:resource order_item
@andywenk
andywenk / gist:3491737
Created August 27, 2012 19:52
orders form
ActiveAdmin.register Order do
form do |f|
f.inputs do
f.input :user_id,
:as => :select,
:collection => User.all.map{ |u| ["#{u.last_name}, #{u.first_name}", u.id] }
end
f.buttons
end
end
@andywenk
andywenk / gist:3491748
Created August 27, 2012 19:53
orders show
show do | order |
attributes_table do
row :id
row :user_id do
user = User.find(order.user_id)
link_to("#{user.first_name} #{user.last_name}", admin_user_path(order.user_id))
end
row :created_at
row :updated_at
@andywenk
andywenk / gist:3491753
Created August 27, 2012 19:54
order items
ActiveAdmin.register OrderItem do
form do |f|
f.inputs do
f.input :order_id,
:as => :select,
:collection => Order.all.map { |order| order.id }
f.input :product_id,
:as => :select,
:collection => Product.all.map { |product| [product.name, product.id] }
f.input :quantity
@andywenk
andywenk / gist:3491755
Created August 27, 2012 19:55
order_items index
index do
id_column
column :order_id
column :product_id do |item|
Product.find(item.product_id).name
end
column :quantity
column :created_at
default_actions
end