我的视图/帮助程序中的以下代码错误地出现了无效对象,但是当我在控制台中运行相同的代码时,它似乎有效。我感谢您提供的任何帮助。
这不起作用 -
2.2.1 :032 > purchase_orders.map do |purchase_order|
2.2.1 :033 > [ERB::Util.h(purchase_order.name),
2.2.1 :034 > ERB::Util.h(purchase_order.descr),
2.2.1 :035 > link_to("Copy PO", purchase_order_copy_path(purchase_order))]
2.2.1 :036?> end
NoMethodError: undefined method `purchase_order_copy_path' for main:Object
from (irb):36:in `block in irb_binding'
from /home/a/.rvm/gems/ruby-2.2.1/gems/activerecord-4.0.13/lib/active_record/relation/delegation.rb:13:in `map'
from /home/a/.rvm/gems/ruby-2.2.1/gems/activerecord-4.0.13/lib/active_record/relation/delegation.rb:13:in `map'
from (irb):32
from /home/a/.rvm/gems/ruby-2.2.1/gems/railties-4.0.13/lib/rails/commands/console.rb:90:in `start'
from /home/a/.rvm/gems/ruby-2.2.1/gems/railties-4.0.13/lib/rails/commands/console.rb:9:in `start'
from /home/a/.rvm/gems/ruby-2.2.1/gems/railties-4.0.13/lib/rails/commands.rb:62:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
这个适用于控制台 -
2.2.1 :037 > app.purchase_order_copy_path(purchase_orders.first)
=> "/purchase_orders/1/copy"
答案 0 :(得分:0)
感谢Rob Cameron,我所要做的就是在我的数据表类中使用Rails.application.routes.url_helpers.purchase_order_copy_path