gottfrois / link_thumbnailer

Ruby gem that fetches images and metadata from a given URL. Much like popular social website with link preview.
MIT License
512 stars 106 forks source link

Basic instructions needed for Rails #117

Closed knzudgt closed 7 years ago

knzudgt commented 7 years ago

I installed link_thumbnailer as described, adding the gem in the Gemfile and then running bundle install. Then I generated the configuration file as suggested with: rails g link_thumbnailer:install. However I did not change the default configuration values.

I would like to use link_thumbnailer in the application I created starting form Michael Hartl's Ruby on Rails tutorial, which is a Twitter-like application that allows users to post microposts with images.

What I expected is the gem to generate an image thumbnail from a given URL copied and pasted in the textarea once I created the micropost, so the URL string with the thubnail below. However the newly created micropost shows only the URL string.

I wonder if I am missing something. Should I add require 'link_thumbnailer' or anything else somewhere?

I am using the following code:

<%= form_for(@micropost, html: { multipart: true }, remote: true) do |f| %>
  <%= render 'shared/error_messages', object: f.object %>
  <div class="field">
    <%= f.text_area :content, placeholder: "Compose new micropost..." %>
  </div>
  <%= f.submit "Post", class: "btn btn-primary" %>
  <span class="picture">
    <%= f.file_field :picture, accept: 'image/jpeg,image/gif,image/png', onchange: "previewFile()" %>
    <img src="" class="img-preview">
  </span>  
<% end %>

screenshot from 2017-07-02 13 53 53

gottfrois commented 7 years ago

I don't know how you implemented your application. When you generate a thumbnail using LinkThumbnailer, you will get an object in response with URL, title, and images attributes.

I invite you to take a look at the readme.