Updates.
This commit is contained in:
parent
9615ecfaac
commit
b3eea95eef
|
@ -0,0 +1,67 @@
|
|||
title: ActiveAdmin
|
||||
---
|
||||
|
||||
### Listing scopes
|
||||
|
||||
Allows you to filter listings by a certain scope.
|
||||
|
||||
scope :draft
|
||||
scope :for_approval
|
||||
|
||||
### Sidebar filters
|
||||
|
||||
filter :email
|
||||
filter :username
|
||||
|
||||
### Custom actions
|
||||
|
||||
You can define custom actions for models.
|
||||
|
||||
before_filter only: [:show, :edit, :publish] do
|
||||
@post = Post.find(params[:id])
|
||||
end
|
||||
|
||||
Make the route:
|
||||
|
||||
member_action :publish, method: :put do
|
||||
@post.publish!
|
||||
redirect_to admin_posts_path, notice: "The post '#{@post}' has been published!"
|
||||
end
|
||||
|
||||
Link it in the index:
|
||||
|
||||
index do
|
||||
column do |post|
|
||||
link_to 'Publish', publish_admin_post_path(post), method: :put
|
||||
end
|
||||
end
|
||||
|
||||
And link it in show/edit:
|
||||
|
||||
action_item only: [:edit, :show] do
|
||||
@post = Post.find(params[:id])
|
||||
link_to 'Publish', publish_admin_post_path(post), method: :put
|
||||
end
|
||||
|
||||
### Columns
|
||||
|
||||
column :foo
|
||||
|
||||
column :title, sortable: :name do |post|
|
||||
strong post.title
|
||||
end
|
||||
|
||||
### Other helpers
|
||||
|
||||
# Grey, green, orange, red
|
||||
status_tag "Done"
|
||||
status_tag "Finished", :ok
|
||||
status_tag "You", :warn
|
||||
status_tag "Failed", :error
|
||||
|
||||
### Disabling 'new post'
|
||||
|
||||
ActiveAdmin.register Post do
|
||||
actions :index, :edit
|
||||
# or: config.clear_action_items!
|
||||
end
|
42
canvas.md
42
canvas.md
|
@ -8,16 +8,43 @@
|
|||
// x = 10, y = 20, width = 200, height = 100
|
||||
c.fillStyle = '#ff0000';
|
||||
c.strokeStyle = '#ff00ff';
|
||||
|
||||
c.lineWidth = 5;
|
||||
c.lineCap = 'round';
|
||||
|
||||
c.fillRect(10, 20, 200, 100);
|
||||
|
||||
c.stroke();
|
||||
c.fill();
|
||||
|
||||
### Saving and restoring
|
||||
|
||||
c.save();
|
||||
|
||||
// Saves:
|
||||
// strokeStyle fillStyle globalAlpha lineWidth lineCap lineJoin miterLimit
|
||||
// shadowOffsetX shadowOffsetY shadowBlur shadowColor
|
||||
// globalCompositeOperation
|
||||
// Transformations: translate rotate scale transform setTransform
|
||||
// Clipping path
|
||||
|
||||
c.restore();
|
||||
|
||||
### Transformations
|
||||
|
||||
c.translate(0, 0)
|
||||
c.rotate(Math.PI*2/5)
|
||||
c.scale(1.0, 1.0)
|
||||
|
||||
See [MDN: Transformations][xform].
|
||||
|
||||
### Image drawing
|
||||
|
||||
c.drawImage(image, dx, dy, [dw, dh]);
|
||||
/* `image` can be HTML Image/Canvas/Video */
|
||||
|
||||
See [MDN: Images][images].
|
||||
|
||||
### Colors, styles shadows
|
||||
|
||||
c.strokeStyle = '#ff00ff';
|
||||
|
@ -28,6 +55,8 @@
|
|||
c.shadowOffsetBlur = 3.0;
|
||||
c.shadowColor = 'rgba(0,0,0,0.2)';
|
||||
|
||||
See [MDN: Styles][styles].
|
||||
|
||||
### Gradients
|
||||
|
||||
gr = c.createLinearGgadient(x0,y0,x1,y1)
|
||||
|
@ -47,12 +76,11 @@
|
|||
c.arc(...)
|
||||
c.closePath()
|
||||
|
||||
### Text
|
||||
### More resources
|
||||
|
||||
* [Canvas Cheatsheet PDF][pdf]
|
||||
|
||||
|
||||
### Resources
|
||||
|
||||
* [Canvas Cheatsheet PDF][cc]
|
||||
[cc]: http://www.nihilogic.dk/labs/canvas_sheet/HTML5_Canvas_Cheat_Sheet.pdf
|
||||
|
||||
[pdf]: http://www.nihilogic.dk/labs/canvas_sheet/HTML5_Canvas_Cheat_Sheet.pdf
|
||||
[xform]: https://developer.mozilla.org/en-US/docs/Canvas_tutorial/Transformations
|
||||
[styles]: https://developer.mozilla.org/en-US/docs/Canvas_tutorial/Applying_styles_and_colors
|
||||
[images]: https://developer.mozilla.org/en-US/docs/Canvas_tutorial/Using_images
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
title: Pry
|
||||
--
|
||||
|
||||
### cd / ls
|
||||
|
||||
> cd Array
|
||||
|
||||
> ls
|
||||
Array.methods: [] try_convert
|
||||
Array#methods: & * + abbrev assoc at ...
|
||||
|
||||
> ls # All
|
||||
|
||||
> ls -m # Methods
|
||||
> ls -M # Instance methods
|
||||
|
||||
> ls -g # Globals
|
||||
> ls -l # Local vars
|
||||
> ls -c # Constants
|
||||
|
||||
> ls -i # Instance vars
|
||||
|
||||
> ls -G xx # Grey by regex
|
||||
|
||||
### Shell integration
|
||||
|
||||
shell-mode adds dir to the prompt
|
||||
|
||||
pry(main)> shell-mode
|
||||
pry(main):/home/x $
|
||||
|
||||
Commands with `.` are shell commands
|
||||
|
||||
pry(main)> .cat hello.txt
|
||||
|
||||
### Inspection
|
||||
|
||||
> show-method Array#select
|
||||
|
||||
> ri Array#each
|
||||
> cd Gem
|
||||
> show-doc try_activate
|
||||
|
||||
Finding
|
||||
|
||||
> find-method each
|
||||
Array#each
|
||||
Array#each_index
|
||||
Enumerable#each_slice
|
||||
...
|
||||
|
||||
### Editing
|
||||
|
||||
> edit-method Pry#repl
|
||||
|
||||
### Gems
|
||||
|
||||
> gem-cd foo # Switch to gem's dir
|
||||
> gem-install foo
|
||||
> gem-list
|
||||
|
||||
### Misc commands
|
||||
|
||||
> hist # History
|
||||
> wtf? # Trace of recent exception
|
||||
|
||||
### Rails console
|
||||
|
||||
$ pry -r ./config/environment
|
||||
|
||||
### Bonus: hirb
|
||||
|
||||
> table User.all
|
||||
> view User.all
|
||||
> view User.all, fields: %w[id name email]
|
||||
|
||||
### Reference
|
||||
|
||||
* [Pry](https://github.com/pry/pry)
|
||||
* [Hirb](https://github.com/cldwalker/hirb)
|
|
@ -203,8 +203,12 @@ API
|
|||
item.valid?
|
||||
item.invalid?
|
||||
|
||||
* [Guides: callbacks](http://guides.rubyonrails.org/active_record_validations_callbacks.html)
|
||||
|
||||
http://guides.rubyonrails.org/active_record_validations_callbacks.html
|
||||
### Sorting
|
||||
|
||||
posts.order(:title)
|
||||
posts.order(:title).reverse
|
||||
|
||||
### Mass updates
|
||||
|
||||
|
|
Loading…
Reference in New Issue