Rails: How to add link_to with target blank

Viewed 61116

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 btn-primary"

But I would like to use the application_helper to define link_to method.

  1. How do I define the link_to methd in application_helper?
  2. How do I pass the class: "btn btn-large btn-primary" in the link_to method?

Thank you for your assistance...

3 Answers

Up to now for Rails 7, I suggest a more elegant way according to Rails's implementation of link_to:

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