{"id":20586062,"url":"https://github.com/charlotte-ruby/social_engine","last_synced_at":"2025-04-14T21:11:21.995Z","repository":{"id":1481922,"uuid":"1728225","full_name":"charlotte-ruby/social_engine","owner":"charlotte-ruby","description":"Alpha - Basic social functions like friendships, comments, ratings, favorites, etc..","archived":false,"fork":false,"pushed_at":"2023-04-12T06:01:10.000Z","size":173,"stargazers_count":45,"open_issues_count":5,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T09:21:18.167Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/charlotte-ruby.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2011-05-10T14:19:41.000Z","updated_at":"2022-06-13T14:00:29.000Z","dependencies_parsed_at":"2023-07-05T18:49:19.122Z","dependency_job_id":null,"html_url":"https://github.com/charlotte-ruby/social_engine","commit_stats":{"total_commits":21,"total_committers":5,"mean_commits":4.2,"dds":0.7142857142857143,"last_synced_commit":"6f664fb439777212118364b369911b19382b0126"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlotte-ruby%2Fsocial_engine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlotte-ruby%2Fsocial_engine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlotte-ruby%2Fsocial_engine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlotte-ruby%2Fsocial_engine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/charlotte-ruby","download_url":"https://codeload.github.com/charlotte-ruby/social_engine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248961237,"owners_count":21189993,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T07:10:07.414Z","updated_at":"2025-04-14T21:11:21.968Z","avatar_url":"https://github.com/charlotte-ruby.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# social_engine\n\nsocial_engine is a rails engine that provides very basic social functionality that you can attach to any model, including comments, ratings, voting, favorites, user reputation, and friend relations.  This plugin is intended to provide you with building blocks, as opposed to a full blown social networking site.  Each building block is customizable and social_engine provides the controllers, helpers, models and css friendly views.  You just include the helpers in your view, provide any non-default options and customize the look using CSS.  This is only compatible with Rails 3 and Ruby 1.9.2.\n\n## Installation\n\nAdd this to your Gemfile and run \"bundle install\"\n  \n    gem \"social_engine\"\n\nRun the social_engine generator to add the needed migrations and static assets\n  \n    rails g social_engine:install\n    \nIf you plan on using the user reputation module, then you will also need to run that generator, which will alter your 'users' table and add a field named \"reputation\"\n\n    rails g social_engine:user_reputation\n\nRun the migrations\n\n    rake db:migrate\n\nThis will add the following tables to your database:\n\n    comments\n    ratings\n    votes\n    favorites\n    reputations\n    reputation_actions\n    friendings\n\n## Usage\n\nHere is an example of how you would add functionality this on an 'Article' model:\n\n    class Article \u003c ActiveRecord::Base\n      is_sociable\n    end\n    \nWhen you add this line to your model, it makes it rateable, voteable and commentable, and favoriteable.  You can also add the functionality individually if you do not want all 4 social aspects in your model.\n\n    class Article \u003c ActiveRecord::Base\n      is_commentable\n      is_voteable\n      is_rateable\n      is_favoriteable\n    end\n    \nYou will also need to add nested resources to the Article route.  In config/routes.rb:\n\n    resources :articles do\n      resources :comments,:votes,:ratings,:favorites\n    end\n\nMake your user model social and make it have reputation\n\n    class User \u003c ActiveRecord::Base\n      has_reputation\n      is_social\n    end\n\nIf you want users to also be able to 'friend' each other, just add this\n\n    class User \u003c ActiveRecord::Base\n      has_reputation\n      is_social\n      is_friendable\n    end\n\n\n## View helpers\n\nFor most situations, these helpers will suffice.  The view helpers will give you forms, widgets or lists and social_engine provides controllers that will redirect to :back when you submit the forms.  Using HAML for examples, but you can use the same inside \u003c% %\u003e for erb\n    \ncreate up/down/count vote widget (similar to Stack Overflow)\n\n    = vote_widget(@article)\n\nadds 5 radio buttons (by default) and a submit to rate something 1-5\n\n    = rating_form(@article)\n    \nadd a rating form with custom number of radio buttons\n\n    = rating_form(@article, 3)\n\nCreate a default comment form\n\n    = comment_form(@article)\n    \nCreate a comment form using options.  By default, the form will ask for name, email and website.  You can specify which fields you want and the text that should be displayed as the label for each.\n\n    # pass symbols to use the default name and email labels\n    = comment_form(@article, :name , :email)\n    # customize the name label by passing a value\n    = comment_form(@article, :name=\u003e{:label=\u003e\"My Name\"} , :email)\n\nList the comments using defaults\n\n    = comments_list(@article)\n    \nList the comments with options.  Defaults shown, all options are optional.  For the date format, you should use the formats show here: http://snippets.dzone.com/posts/show/2255\n\n    = comments_list(@article, {:display_posted_by =\u003e true, \n                               :display_date =\u003e true, \n                               :date_format =\u003e \"%m/%d/%Y at %H:%M\"})\n\nButton so user can add it to their favorites list.  This button will toggle b/w Add \u0026 Remove\n\n    = favorites_widget(@article)\n\nDefault Tweetme button\n\n    = tweetme\n\nTweetme button with options (all are optional with defaults shown as the values in this example)\n\n    = tweetme(:url =\u003e \"http://mysaweetsite.com\", \n              :text =\u003e \"This website is saweet!\", \n              :via =\u003e \"@cowboycoded\", # appends via to end of tweet\n              :count =\u003e \"horizontal\")  # this will show the tweet count:  horizontal, vertical or none\n\nDefault Facebook Like button\n\n    = fb_like\n\nFacebook Like button with options (all are optional with defaults shown as the values in this example)\n\n    = fb_like(:url =\u003e request.url, \n              :layout =\u003e \"standard\", # standard, button_count or box_count\n              :faces =\u003e true, # true or false\n              :width =\u003e 450, # your choice\n              :action =\u003e \"like\", # like or recommend\n              :font =\u003e \"lucida grande\", # arial, lucida grande, segoi ui, tahoma, trebuchet ms, or verdana\n              :colorscheme =\u003e \"light\",  #light or dark\n              :div_id: \"fblike\")  #your choice\n        \nDefault Facebook Friend box\n\n    = fb_friend_box\n    \nFacebook Friend box with options (all are optional)\n\n    = fb_friend_box( :width =\u003e 250, \n                     :stream =\u003e false, \n                     :header =\u003e true, \n                     :faces =\u003e true, \n                     :fb_page_url =\u003e \"http://www.facebook.com/couponshack\" )\n                     \n                     \n                     \nThe views are meant to be CSS friendly and allow you to adjust the look of every part of the view by overriding the default styles.  You can make changes to public/stylesheets/social_engine.css.\n    \n## Models\n\nYou are not tied to using the provided views and controllers to manage comments, votes, favorites and reputation.  If you prefer your own implementation of controllers \u0026 views, you can still use the functionality of the models.\n\nAgain, you need to make your model sociable first and make your user model have rep and be social\n\n    class Post \u003c ActiveRecord::Base\n      is_sociable\n    end\n    \n    class User \u003c ActiveRecord::Base\n      is_social\n      has_reputation\n    end\n\nOnce your model is sociable, you can add comments, ratings, votes, and favorites in the following ways.  \n\nFirst create an instance of Post, so we can use the social methods that are included when you specify the post is_sociable:\n\n    post = Post.create(:name =\u003e \"post\")\n\n###Voting:\n\nUpvote a post:\n\n    post.upvote\n    post.vote_count #=\u003e 1\n    \nDownvote a post:\n\n    post.downvote\n    post.vote_count #=\u003e -1\n\nCreate a vote and vote value manually:\n \n    post.votes.create(:value =\u003e 99)\n    post.vote_sum #=\u003e 99\n\nDelete all votes for a post:\n\n    post.upvote\n    post.votes.first.destroy\n    post.votes.size #=\u003e 1  Why?? The set is cached\n    post.votes(true) # you have to reload the set by passing true\n    post.votes.size #=\u003e 0\n    \nNOTE: By default, voting is restricted to one per ip_address per object.  There are 2 ways around this:\n1. Set fingerprint_method to \"none\" in config/yettings/social_engine.yml, which will disable the uniqueness validation\n2. pass validate false to the save method to skip validations.  You have to use new/save instead of create like so:\n    \n    vote = post.votes.new(:value=\u003e1)\n    vote.save(false) # or vote.save(:validate=\u003efalse)\n\n###Comments\n\nCreate a comment and attach a user to it\n\n    post.comments.create(:comment =\u003e \"I'm sure whatever your thinking is correct\", :user_id=\u003e123)\n    \nCreate a comment using an anauthenticated user\n\n    post.comments.create(:comment =\u003e \"I'm sure whatever your thinking is correct\", \n                         :unauthenticated_name =\u003e \"ignored name\",\n                         :unauthenticated_email =\u003e \"ignore@email.com\",\n                         :unauthenticated_website =\u003e \"http://ignore.com\")\n\nDestroy a comment\n\n    post.comments.first.destroy\n    post.comments(true)  # remove the cache, so you can get the correct array size if you need it\n\n###Ratings    \n\nCreate a new rating with a user_id\n\n    post.ratings.create(:value=\u003e5, :user_id=\u003e123)\n    \nDestroy a rating for a user_id\n\n    post.ratings.where(:user_id=\u003e123).destroy_all\n    \nDestroy all ratings for a post\n\n    post.ratings.destroy_all\n\n###Favorites\n\n    post.favorites.create(:user_id=\u003e123)\n    User.find(123).favorites #=\u003e outputs the favorite you just created\n\n###Reputation\n\nA primitive admin panel is provided to allow you to adjust reputation action values based on their name.  The names of all reputation actions are pulled directly from \nthe source code and a list is provided at the bottom of the admin panel for your convenience.\n\nThere is a Reputation model and a ReputationAction model.  Reputation stores the reputation_action_id, user_id, and the value.  ReputationAction stores the name of an action, which is defined by you, and the default value.  \nNote that if you change the value, you will have to update the existing records in the reputation table manually.  By default, the reputation table stores the value of the reputation action at the time of creation.\nSo in order for you to add reputation points to a user, you have to define the action and pass the user.  Let's say you have a reputation action called \"answered question\" with a value of 5 points.  And you have a controller \ncalled answers, with a create method.  You would add this method to the controller:\n\n    class AnswersController \u003c ApplicationController\n      def create\n        #do some stuff here to create the answer\n        \n        # add the reputation\n        Reputation.add(\"answered question\", current_user)\n      end\n\nThe method aboves assumes that \"current_user\" returns the logged in user in this session.  This add a record to the reputations table.  If you ran the user_reputation generator shown in the Installation section of this document, then \nthen Reputation.add will also add the value of that reputation action to the \"reputation\" field in the users table.  This field is used to avoid joins and store the sum of all reputation record's values for that user.\n\nAssuming you have the \"reputation\" field in your users table, you just do this to get the total reputation value:\n\n    User.first.reputation\n    \nOr if you choose not to add that field, you can get the reputation this way:\n\n    User.first.reputations.sum(:value)\n\n### Friends\nBy making your User model friendable, you allow users to request friends and to confirm or reject friendship requests that come their way. The friendship model is directional, meaning it distinguishes between the friendor and the friendee. This may be useful for situations where users can \"follow\" others, while having many followers.\n\nYou can have @user request to be friends with @other_user\n\n    @user.add_friend(@other_user)\n\nGet the last user who requested to be friends with @other_user\n\n    @other_user.requesting_friends.last #=\u003e @user\n\nYou can get the same result through the Friending record for that request\n\n    @other_user.friend_requests.last.friendor #=\u003e @user\n\nConfirm the request\n\n    @other_user.friend_requests.last.confirm\n\nOr reject it\n\n    @other_user.friend_requests.last.reject\n\nIf you want your app to skip the confirmation step and automatically activate all friend requests, set confirm_friends to \"false\" in config/yettings/social_engine.yml\n\nYou also get the following instance methods for your users\n\n    @user.friends   #=\u003e Return collection of users that are friends with @user\n    @user.friendors #=\u003e Only list friends that have requested friendship with @user\n    @user.friendees #=\u003e Only list friends that @user has requested friendship with\n\nThese methods return only friends that are confirmed and not rejected. To get info on unconfirmed friends:\n\n    @user.pending_friends    #=\u003e Return users that have not confirmed friendship requests from @user.\n                             #   This will include users that have rejected a friendship request from @user.\n    @user.requesting_friends #=\u003e Return users that have requested to be friends with @user, but which @user has not confirmed\n    @user.rejected_friends   #=\u003e users from which @user has rejected a friendship request\n\nThe above methods are all associated with collections of Friending instances, which can be obtainer from the friendorings, friendeeings, pending_friendships, friend_requests, and friend_rejections instance methods for User.\n\n## Development Roadmap / TODO\n###Features\n1. More helpers for reputation\n2. Ajax methods for controllers \u0026 views, so you don't have to redirect_to :back\n3. Improve CSS and views\n\n###Behind the scenes\n1. Better test coverage\n2. Refactoring and DRYing (mainly tests)\n\n\n\n## Contributing to social_engine\n \n* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet\n* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it\n* Fork the project\n* Start a feature/bugfix branch\n* Commit and push until you are happy with your contribution\n* Make sure to add tests.  Patches will not be accepted without Rspec or Cucumber tests.\n* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.\n\n## Copyright\n\nCopyright (c) 2011 John McAliley. See LICENSE.txt for\nfurther details.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharlotte-ruby%2Fsocial_engine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcharlotte-ruby%2Fsocial_engine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharlotte-ruby%2Fsocial_engine/lists"}