Look interesting right? :)
It change my perspective. Why don't you try it!
It change my perspective. Why don't you try it!
namespace :admin do
resources :menus do
resources :menu_items
end
end
I think it's probably common used case. Unfortunately, I got this error when I try to create a new MenuItem in menu_items/_form.html.erb
undefind method 'admin_menu_items_path' for #<#<Class ...
...
1: <%= form_for(@admin_menu_item)do |f| %>
...
17: end
I realize that the standard scaffolding won't work for me, so I start googling. Right away, I get a lot of hits. It's seem to be a common issue. However, the solutions create quite a confusion for me. I try different solutions, some looking good but don't work! .. Here is what I find working.def new @menu = Admin::Menu.find(params[:menu_id]) @menu_item = @menu.menu_items.build ... endIt load up the @menu, and build @menu_item, nothing surprise me. I also get rid of than "admin" prefix. It's simpler that way.
1: def perms(L) 2: return [[]] if L.size == 0 3: result = [] 4: L.each do |elm| 5: L1 = L - [elm] 6: perms(L1).each |p| 7: p1 = [elm] + p 8: result << p1 9: end 10: end 11: return result 12: end
When I was a kid, I used to practice Chinese Abacus every day. Me and my brother turn this boring practice into a competition, and the winner is the person who can do 1 + 2 + ... + 100 faster! Of course, it's has to be correct. At that time, we were told that the correct value is 5050, and we did not question about it.1 + 2 + 3 + ... + 100 100 + 99 + 98 + ... + 1 --------------------------------------- 101 + 101 + 101 + ... + 101 = 101 * 100
Mathjax is an open source Javascript display engine for mathematics. It's allow you to rendered math equation on all modern browsers without have to download reader, plugins or fonts.When \(a \ne 0\), there are two solutions to \(ax^2 + bx + c = 0\)
and they are $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
<script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js? config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script>
Previously in the programming series posts, I show how to use module to implement composition. One limitation of using module is, duck can not change behavior at run time. Such as MallardDuck can only fly with wing. How can we allow an instance of duck to change their behavior at run time? An answer is using object instead of module.class Duck
attr_reader :name
attr_accessor :fly_behavior, :quack_behavior
def initialize
@name = "mallard duck"
@fly_behavior = nil
@quack_behavior = nil
end
def fly
fly_behavior.fly
end
def quack
quack_behavior.quack
end
end
require './duck'
require './behavior/fly_with_wing'
require './behavior/quack_loud'
class MallardDuck < Duck
def initialize
@name = "mallard duck"
@fly_behavior = Behavior::FlyWithWing.new
@quack_behavior = Behavior::QuackLoud.new
end
end