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
: 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' |
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 '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" |
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
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 |
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 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 |
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
bundle install | |
rails generate active_admin:install | |
rake db:migrate | |
rails s |
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
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 |
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
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 |
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
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 |
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
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 |
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
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 |