Change for getting url from key

This commit is contained in:
Christophe Vilayphiou 2012-08-08 07:46:10 +08:00
parent f7e6703d5f
commit db16fdc7b5
5 changed files with 8 additions and 7 deletions

View File

@ -9,7 +9,6 @@ window.SocialShareButton =
img = encodeURIComponent($(el).parent().data("img"))
fb_url = encodeURIComponent($(el).parent().data("fb_url"))
url = encodeURIComponent(location.href)
fb_full_url = encodeURIComponent("#{fb_url}?orig_host=#{location.host}&orig_path=#{location.pathname}")
switch site
when "weibo"
SocialShareButton.openUrl("http://v.t.sina.com.cn/share/share.php?url=#{url}&pic=#{img}&title=#{title}&content=utf-8")
@ -18,7 +17,7 @@ window.SocialShareButton =
when "douban"
SocialShareButton.openUrl("http://www.douban.com/recommend/?url=#{url}&title=#{title}&image=#{img}")
when "facebook"
SocialShareButton.openUrl("http://www.facebook.com/sharer.php?t=#{title}&u=#{fb_full_url}")
SocialShareButton.openUrl("http://www.facebook.com/sharer.php?t=#{title}&u=#{fb_url}")
when "qq"
SocialShareButton.openUrl("http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=#{url}&title=#{title}&pics=#{img}")
when "tqq"

View File

@ -110,7 +110,9 @@ class ApplicationController < ActionController::Base
def render_share
object_class = params[:model].classify.constantize
@object = object_class.find(params[:id])
@orig_url = "http://#{params[:orig_host]}/#{params[:orig_path]}"
module_app = ModuleApp.first(:conditions => {:key => params[:key]})
@item = Item.where(module_app_id: module_app.id).all_of("tag" => {"$in" => [nil,'']},"category" => { "$in" => [nil,'']}).first
@orig_url = "http://#{request.host}/#{@item.path}?id=#{@object.id}"
render 'shared/render_share', :layout => false
end

View File

@ -215,13 +215,13 @@ module ApplicationHelper
object.strftime("%Y-%m-%d")
end
def share_links(object)
def share_links(object, key)
js = ''
js << "<meta property='og:title' content='#{object.title}' />\n" rescue ''
js << "<meta property='og:description' content='#{object.subtitle}' />\n" rescue ''
js << "<meta property='og:image' content='#{object.image.url}' />\n" rescue ''
content_tag :div, :class => 'fb' do
concat social_share_button_tag(object.title, :fb_url => "http://#{request.env['HTTP_HOST']}/share/#{object.class.to_s.underscore}/#{object.id}", :image => "http://#{request.env['HTTP_HOST']}#{object.image.url}")
concat social_share_button_tag(object.title, :fb_url => "http://#{request.env['HTTP_HOST']}/share/#{object.class.to_s.underscore}/#{object.id}?key=#{key}", :image => "http://#{request.env['HTTP_HOST']}#{object.image.url}")
# concat javascript_tag "$('head').append('#{j js}');"
end
end

View File

@ -37,4 +37,4 @@
<% end %>
</div>
<%= share_links(@news_bulletin) %>
<%= share_links(@bulletin, 'announcement') %>

View File

@ -39,4 +39,4 @@
<% end %>
</div>
<%= share_links(@news_bulletin) %>
<%= share_links(@news_bulletin, 'news') %>