Votex v0.2.0 Votex.Votable View Source

Defines a Votable Model

A Votable model will expose the required methods to enable voting functionality Typically be used by models like Post, Image, Answer etc.

Example

defmodule Post do  
  use Ecto.Schema 
  use Votex.Votable
  schema "posts" do 
    field :title, :string 
    field :views, :integer, default:  0 
  end  
end

Link to this section Summary

Functions

Primary method to remove a vote

Primary method to cast a vote

Get a list of votes on votable record

Link to this section Functions

Link to this function unvote_by(votable, voter) View Source

Primary method to remove a vote

Example

{:ok, vote} = post |> Post.unvote_by user

Primary method to cast a vote

Example

{:ok, vote} = post |> Post.vote_by user

Get a list of votes on votable record

Example

votes = post |> Post.votes_for