Created
January 8, 2012 22:23
-
-
Save RyanFriedman/1579930 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post < ActiveRecord::Base | |
attr_accessor :position, :follower_id | |
has_many :relationships, :dependent => :destroy, | |
:foreign_key => "follower_id" | |
has_many :reverse_relationships, :dependent => :destroy, | |
:foreign_key => "followed_id", | |
:class_name => "Relationship" | |
has_many :followers, :through => :reverse_relationships, | |
:source => :follower | |
accepts_nested_attributes_for :relationships | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Relationship < ActiveRecord::Base | |
attr_accessible :followed_id, :latitude | |
belongs_to :follower, :class_name => "User" | |
belongs_to :followed, :class_name => "Post" | |
validates :follower_id, :presence => true | |
validates :followed_id, :presence => true | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RelationshipsController < ApplicationController | |
def sort | |
params[:post].each_with_index do |id, index| | |
Relationship.update_all({position: index+1}, {id: id}) | |
end | |
render nothing: true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment