link_to咖啡助手与数据属性

时间:2012-08-09 10:27:43

标签: ruby-on-rails-3 coffeescript helper link-to custom-data-attribute

我有@link_to js.coffee助手

@link_to = (body, url, html_options = {}) =>
  html_options["href"] = url
  @content_tag("a", body, html_options)

@html_options_to_s = (html_options) =>
  if $.isPlainObject(html_options)
    (" #{key}=\"#{value}\""  for key, value of html_options  when typeof value isnt "undefined").join("")
  else
    ""

@content_tag = (tag_name, content, html_options) =>
  "<#{tag_name}#{@html_options_to_s html_options}>#{content}</#{tag_name}>"

如何使其适用于具有数据属性的链接?例如:

= link_to "", "#", data: {save_url: "/projects/#{@keyword.get("project_id")}/keywords/#{@keyword.id}"}

输出:

<a href="#" data="[object Object]"></a>

0 个答案:

没有答案