0

我目前正在编写一个基于引导程序的自定义表单助手,但我遇到了依赖问题(我认为):

class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
  include ActionView::Helpers::UrlHelper
  include ActionView::Helpers::OutputSafetyHelper

  alias :super_collection_select :collection_select

  def collection_select_append(method, collection, value_method, text_method, options = {}, html_options = {})
    ('<div class="control-group' + has_error(object.errors[method]) + '">' +
      label(method, :class => "control-label") +
      '<div class="controls">' +
        '<div class="input-append">' +
          super_collection_select(method, collection, value_method, text_method, objectify_options(options), @default_options.merge(html_options)) +
          '<span class="add-on">' +
            link_to(raw("<i class\"icon-white icon-ok\"></i>"), {:controller => "myController", :action => "myAction"}, :method => "post", :remote => true, :html => { :val1 => "val1", :val2 => "val2" } ) +
          '</span>' +
        '</div>' +
        get_error_message(object.errors[method]) +
      '</div>' +
    '</div>').html_safe
  end

end

这将返回一个错误:

undefined local variable or method `controller' for #<..>
4

1 回答 1

0

我认为您:url在此错过了控制器的选项:

link_to(raw("<i class\"icon-white icon-ok\"></i>"), {:controller => "myController", :action => "myAction"}, :method => "post", :remote => true, :html => { :val1 => "val1", :val2 => "val2" } )

尝试:

class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
  include ActionView::Helpers::UrlHelper
  include ActionView::Helpers::OutputSafetyHelper

  alias :super_collection_select :collection_select

  def collection_select_append(method, collection, value_method, text_method, options = {}, html_options = {})
    ('<div class="control-group' + has_error(object.errors[method]) + '">' +
      label(method, :class => "control-label") +
      '<div class="controls">' +
        '<div class="input-append">' +
          super_collection_select(method, collection, value_method, text_method, objectify_options(options), @default_options.merge(html_options)) +
          '<span class="add-on">' +
            link_to(raw("<i class\"icon-white icon-ok\"></i>"), :url => {:controller => "myController", :action => "myAction"}, :method => "post", :remote => true, :html => { :val1 => "val1", :val2 => "val2" } ) +
          '</span>' +
        '</div>' +
        get_error_message(object.errors[method]) +
      '</div>' +
    '</div>').html_safe
  end

end
于 2013-02-13T13:08:15.363 回答