Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
ActiveRecord extension that turns your models into facebook opengraph objects.
gem install acts_as_opengraph
Now just add the gem dependency in your projects configuration.
# app/models/movie.rb
class Movie < ActiveRecord::Base
acts_as_opengraph
end
# app/views/layouts/application.html.erb
<head>
<%= yield :opengraph_meta_tags %>
</head>
# app/views/movies/show.html.erb
<% content_for :opengraph_meta_tags, opengraph_meta_tags_for(@movie) %>
# app/views/movies/show.html.erb
<%= like_button_for @movie %>
* Notice that the Like Button will retrieve the required href
attribute by calling @movie.opengraph_url
. Read below for more options.
Even when the names of these columns can be changed with configuration, acts_as_opengraph
tries to guess these names by checking for the existence of common names. Chances are that your model already has some of the opengraph defined properties.
This is the list of supported opengraph protocol properties and their possible column names (in precedence order):
If you need to use a different column then use the columns option. For example, if you store the url of your movies using the imdb_url
column in your movies table, then do this:
# app/models/movie.rb
acts_as_opengraph :columns => { :url => :imdb_url }
If you wish to use a custom method for some opengraph field, then all you need to do is to define a method with the prefix opengraph_
.
For example, if you are using Paperclip for your image attachments, you can do this:
# app/models/movie.rb
class Movie < ActiveRecord::Base
has_attached_file :picture, :styles => { :small => "160x130>"}
acts_as_opengraph
def opengraph_image
picture.url(:small)
end
end
Use the values option for passing default opengraph values. For our Movie example we can specify that all of our records are movies by doing this:
acts_as_opengraph :values => { :type => "movie" }
* Notice that acts_as_opengraph
only accepts an options hash argument, so if you want to combine default values and column names you'd do this:
acts_as_opengraph :columns => { :url => :imdb_url, :email => :contact },
:values => { :type => "movie", :site_name => "http://example.com" }
Along with the object for which you want to display the Like button, you can pass an options hash to configure its appearance:
# app/views/layouts/application.html.erb
<%= like_button_for @movie, :layout => :box_count, :show_faces => true %>
By default, acts_as_opengraph
will try to retrieve your object's url by calling opengraph_url
on it. You could override it by defining a custom method, like this:
# app/models/movie.rb
def opengraph_url
"http://example.com/movies/#{self.id}"
end
But that's not the Rails way, so instead of doing that, you can pass an href
option from your views, which means you can easily take advantage of the url helpers, like this:
# app/views/movies/show.html.erb
<%= like_button_for @movie, :href => movie_path(@movie) %>
See the complete list of allowed attributes and options here.
The XFBML version is more versatile, but requires use of the JavaScript SDK.
# app/views/movies/show.html.erb
# You can use the following helper method to load the JavaScript SDK
<%= fb_javascript_include_tag YOUR_APP_ID %>
# Now you can pass the :xfbml option to the like button helper
<%= like_button_for @movie, :xfbml => true %>
Copyright © 2011 Ruben Ascencio, released under the MIT license
FAQs
Unknown package
We found that acts_as_opengraph demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.