Rails: How to add link_to with target blank

后端 未结 2 701
逝去的感伤
逝去的感伤 2021-02-11 12:07

I am new to rails 3, I would like to add (:target => \"_blank\") to link_to helper below

link_to \"GOOGLE\", \'http://www.google.com\', class: \"btn btn-large b         


        
2条回答
  •  甜味超标
    2021-02-11 12:32

    Adding to Anthony's answer, this more closely resembles Rails' link_to implementation, including support for blocks and passing no parameters:

    def link_to_blank(name = nil, options = nil, html_options = nil, &block)
      target_blank = {target: "_blank"}
      if block_given?
        options ||= {}
        options = options.merge(target_blank)
      else
        html_options ||= {}
        html_options = html_options.merge(target_blank)
      end
      link_to(name, options, html_options, &block)
    end
    

提交回复
热议问题