新手问题 button_to_function 替换方法

lyzrnkfg · 2017年01月20日 · 最后由 lyzrnkfg 回复于 2017年01月20日 · 1437 次阅读
def button_to_function(name, function=nil, html_options={})
  message = "button_to_function is deprecated and will be removed from Rails 4.1. We recommend using Unobtrusive JavaScript instead. " +
    "See http://guides.rubyonrails.org/working_with_javascript_in_rails.html#unobtrusive-javascript"
  ActiveSupport::Deprecation.warn message

  onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function};"

  tag(:input, html_options.merge(:type => 'button', :value => name, :onclick => onclick))
end

版本升级后有什么替换方法?

def button_to_csv(name, options = {})
    button_to_function name, "reloadWithFormat('csv','normal');", options
  end

我直接用 tag(:input, options.merge(:type => 'button', :value => name, :onclick => "reloadWithFormat('csv','normal');")) 不知道有没有别的

需要 登录 后方可回复, 如果你还没有账号请 注册新账号