【发布时间】:2020-09-05 05:40:46
【问题描述】:
我有这个 index.html.erb,它是我的帖子菜单:
<%provide(:title, "Recipes") %>
<div class="search_container">
<%= form_tag(posts_path, :method => 'get', id: "search-form") do %>
<%= text_field_tag :search,params[:search], placeholder: "Search Tags" %>
<%= submit_tag "Search" %>
<% end %>
</div>
<div class="tag_container">
<div class="tag_cloud tag_cloud_positioning_and_color_and_stuff">
<% tag_cloud Post.tag_counts, %w{s m l} do |tag, css_class| %>
<%= link_to tag.name, tag_path(tag.id), class: css_class %>
<% end %>
</div>
</div>
<div class="posts_wrapper">
<% @posts.each do |post| %>
<div class="card-group card-group-size">
<div class="card recipes recipes_posts">
<%= link_to post do %>
<img src="<%= url_for(post.image) if post.image.attached? %> " class="index_images">
<% end %>
<div class="card-body card_body_size">
<h5 class="card-title"><%=link_to post.title, post, class: "post_title"%></h5>
</div>
</div>
</div>
<% end %>
<%= will_paginate @posts %>
</div>
当我从菜单中选择一个帖子时,show.html.erb 会按照特定的 post_id 呈现。以这种格式,它与附加的图像共享正确的帖子:(在 benj-p 用 给我的想法后修改):
<head>
<meta property="og:url" content="https://secretstrawberry.herokuapp.com/posts/<%= @post.id %>" />
<meta property="og:type" content="website" />
<meta property="og:title" content="<%= @post.title %>" />
<meta property="og:image" content="<%= image_tag @post.image %>" />
</head>
<div id="fb-root"></div>
<script async defer crossorigin="anonymous"
src="https://connect.facebook.net/en_GB</sdk.js#xfbml=1&version=v7.0&appId=2751510331745380&autoLogAppEvents=1">
</script>
<%provide(:title, @post.title) %>
<div class="recipe_container">
<% if logged_in? && current_user.admin? %>
<div class="edit_delete_buttons_container">
<div class="edit_delete_buttons">
<%= link_to "Edit", edit_post_path(@post), {:class => "img_button btn btn-success button_back"} %>
</div>
<div class="edit_delete_buttons">
<%= link_to "Delete", post_path(@post), method: :delete, data: { confirm: "Are you sure?" },
class: "img_button btn btn-danger" %>
</div>
</div>
<% end %>
<div class="fb-share-button" data-href="https://secretstrawberry.herokuapp.com/posts/<%= @post.id %>"
data-layout="button_count" data-size="small"><a target="_blank"
href="https://www.facebook.com/sharer/sharer.php?u=<%= posts_path(@post) %>&src=sdkpreparse"
class="fb-xfbml-parse-ignore">Share</a></div>
<div class="tags tags_in_recipe_show">
Tags:<%= render @post.tags %>
</div>
<div class="signup_h1 post_new_button h1_show">
<h1 id=""><strong><%= @post.title %></strong></h1>
</div>
<div class="image_container">
<% if @post.image.attached? %>
<%= image_tag @post.image, class: "image_view" %>
<% end %>
</div>
<div class="recipe_body">
<div class="margin_top_ingredients">
<pre class="ingredients">
<%= @post.content %>
</pre>
</div>
<div>
<pre class="ingredients">
<%= @post.method %>
</pre>
</div>
<div>
<pre class="ingredients">
<%= @post.description %>
</pre>
</div>
</div>
<div class="recipe_body comments_container ">
<p id="comment_count"><%= @post.comments.count %> reviews <%= link_to "Log In", login_path unless logged_in? %> </p>
<%= render @post.comments.order("created_at DESC").paginate(page: params[:page], per_page: 5)%>
<div class="form_container_post">
<%= render 'comments/form' %>
<div class="paginate">
<%= will_paginate @comments %>
</div>
</div>
</div>
</div>
现在这个 facebook 分享按钮正在工作,分享帖子标题和帖子图片。
谢谢。
【问题讨论】:
标签: javascript jquery ruby-on-rails