Link_to从类中删除按钮:无法将String转换为Hash

时间:2014-09-25 13:21:12

标签: ruby-on-rails ruby

我有这个简单的Ruby类(我在控制器中使用它来创建产品集合):

class ProductDashboardDecorator
    include ApplicationHelper
    include ActionView::Helpers::NumberHelper
    include ActionView::Helpers::TagHelper
    include ActionView::Helpers::AssetTagHelper
    include ActionView::Helpers::UrlHelper
    include ActionController::UrlWriter

    def initialize(p)
        @product = p
    end

    def special_links
        ret = ''
         # this works!
         ret << content_tag(:a, 'X', :href => removee_product_path(@product), :title => 'rimuovi', :class => 'remove_link', :method => :delete)

         # this don't!
         ret << link_to('X', removee_product_path(@product), :title => 'rimuovi', :class => 'remove_link', :method => :delete)

        return ret.html_safe
    end
end

我想使用link_to创建一个“删除”按钮。但是当我这样做时,我得到了这个错误:

can't convert String into Hash

这些是路线:

map.resources :products, :member => { :removee => :delete }, :as => 'prodotti' do |product|
    product.resources :watchers, :collection => { :add => :get }
  end

任何帮助?

1 个答案:

答案 0 :(得分:0)

尝试使用此语法,未经过测试

content_tag(:span, link_to('X', removee_product_path(@product), :title => 'rimuovi', :class => 'remove_link', :method => :delete))