Skip to content

Instantly share code, notes, and snippets.

@jhjguxin
Last active October 1, 2020 18:58
Show Gist options
  • Save jhjguxin/4544826 to your computer and use it in GitHub Desktop.
Save jhjguxin/4544826 to your computer and use it in GitHub Desktop.
delegate demo, use helpers and url_helper outside controller or helpers ....
## rails runner script/generate_source_tracker_link.rb
#eg: version_number: 20130116-1-1 #data-1(早)/2(晚)-1(article_number)
class GeneraterSourceTracker
#include ActionView::Helpers
#include ActionView::Helpers::UrlHelper
include Rails.application.routes.url_helpers
delegate :url_helpers, to: 'Rails.application.routes'
delegate :helpers, to: 'ActionController::Base'
def tracker_url(source_tracker)
#new_source_tracker_url(source_tracker: source_tracker, host: "cms.bbtang.com")
url_helpers.new_source_tracker_url(source_tracker: source_tracker, host: "cms.bbtang.com")
end
def image_tracker(source_tracker)
helpers.image_tag(tracker_url(source_tracker), width: "0", height: "0", alt: "")
end
end
generater_source_tracker = GeneraterSourceTracker.new
source_tracker = {platform: "weixin", from: "fumutang", version_number: "20130116-1-1"}
html = generater_source_tracker.image_tracker(source_tracker)
puts html.html_safe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment