I have added the emdedly-ruby gem (https://github.com/embedly/embedly-ruby) to my social bookmarking appliction. Embedly pulls in an image from a url and replaces the url link with the image in my application. It is working perfectly in local, but it doesn't work in production (Heroku). I am new to programming and I do not know how to capture an error in production. Any suggestions would be much appreciated!
Here is my bookmark.rb model file:
class Bookmark < ActiveRecord::Base
#attr_accessible :thumbnail_url
has_many :bookmark_topics
has_many :topics, through: :bookmark_topics
has_many :user_bookmarks
has_many :users, through: :user_bookmarks
has_many :likes, dependent: :destroy
default_scope { order('updated_at DESC') }
after_create :set_embedly_url
private
def set_embedly_url
embedly_api = Embedly::API.new :key => ENV['EMBEDLY_API_KEY'],
:user_agent => 'Mozilla/5.0 (compatible; mytestapp/1.0; my@email.com)'
Rails.logger.info ">>>> embedluy object: #{embedly_api.inspect}"
obj = embedly_api.extract :url => self.url
Rails.logger.info ">>>> embedly obj: #{obj.inspect}"
# get result and find the attribute for the thumbnail_url
# set the bookmark's thumbnail_url with that value -- update_attribute(thumbnail_url: val_of_thumbnail_url_from_response)
o = obj.first
Rails.logger.info ">>>> o: #{o.inspect}"
image = o.images.first
Rails.logger.info ">>>>> image: #{image.inspect}"
update_attribute(:thumbnail_url, image['url'])
Rails.logger.info ">>>> Now i am: #{self.inspect}"
true
end
end
Here is my bookmark.html.erb partial file in views:
<div class="btn-group">
<% show_remove_button ||= false %>
<li>
<div class="bookmark_container">
<div class="thumbnail">
<% link_text = bookmark.thumbnail_url.present? ? "<img src='#{bookmark.thumbnail_url}'/>".html_safe : bookmark.url %>
<%= link_to link_text, bookmark.url %>
</div>
</div>
<% if current_user %>
<div class="like">
<% if show_remove_button %>
<% user_bookmark = get_user_bookmark_for(bookmark) %>
<% if user_bookmark %>
<%= link_to "Remove", user_bookmark_path(user_bookmark), class: 'btn btn-danger', method: :delete %>
<% end %>
<% else %>
<% if like = current_user.liked(bookmark) %>
<%= link_to [bookmark, like], class: 'btn btn-info', method: :delete do %> Unlike <% end %>
<% else %>
<%= link_to [bookmark, Like.new], class: 'btn btn-info', method: :post do %> Like <% end %>
<% end %>
<% end %>
</div>
<% end %>
</li>
and here is my application.js file in my javascript folder:
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require_tree .
Here is my gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.5'
group :development, :test do
gem 'rspec-rails'
gem 'capybara'
end
group :production do
gem 'pg'
gem 'rails_12factor'
end
group :development do
gem 'sqlite3'
end
gem 'bootstrap-sass', '~> 3.1.1'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.2'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
gem 'devise'
gem 'faker'
gem 'figaro'
gem 'embedly'
Please let me know if there are any other files you would like to see. I have also read through embedly tutorials at http://embed.ly/docs/api/tutorials, but I am not using jquery in my code to make embedly work, as they are using in the tutorials. Do you think I am required to use jquery in my code to make it work? But then why would embedly work in local without jquery and not in production?