Note that there are some explanatory texts on larger screens.

plurals
  1. PODont Follow Inviter on SIgnUp if Admin User
    primarykey
    data
    text
    <p>I have created a BETA Invitation system by following this tutorial. <a href="http://railscasts.com/episodes/124-beta-invitations" rel="nofollow">http://railscasts.com/episodes/124-beta-invitations</a>. Users can also follow one another in my Rails app.</p> <p><strong>Currently, I have two methods:</strong></p> <ol> <li><p>Allows the User to follow all ADMIN USERS on Sign up.</p></li> <li><p>Allows the User to follow INVITER on sign up.</p></li> </ol> <p><strong>The problem I am having is:</strong> </p> <pre><code>no such column: TRUE: SELECT DISTINCT "users".* FROM "users" INNER JOIN "invitations" ON "invitations"."id" = "users"."invitation_id" WHERE (invitations.recipient_email = 'spedroza@usc.edu' OR users.admin IS TRUE) </code></pre> <p>Is there anyway to fix the second method so it wont follow the inviter if he is an ADMIN USER?</p> <p><strong>MODEL</strong></p> <p>USER</p> <pre><code>class User &lt; ActiveRecord::Base attr_accessible :name, :email, :password, :password_confirmation, :invitation_token has_many :relationships, foreign_key: "follower_id", dependent: :destroy has_many :followed_users, through: :relationships, source: :followed has_many :reverse_relationships, foreign_key: "followed_id", class_name: "Relationship", dependent: :destroy has_many :followers, through: :reverse_relationships, source: :follower has_many :sent_invitations, :class_name =&gt; 'Invitations', :foreign_key =&gt; 'sender_id' belongs_to :invitation after_create follow_inviter_and_admins #--------HERE!! def follow_inviter_and_admins #--------HERE!! return true if admin? users = User.joins(:invitation).where('invitations.recipient_email = ? OR users.admin IS admin', email).uniq users.each do |user| self.follow!(user) end end def invitation_token invitation.token if invitation end def invitation_token=(token) self.invitation = Invitation.find_by_token(token) end def following?(other_user) relationships.find_by_followed_id(other_user.id) end def follow!(other_user) relationships.create!(followed_id: other_user.id) end end </code></pre> <p>RELATIONSHIPS</p> <pre><code>class Relationship &lt; ActiveRecord::Base attr_accessible :followed_id belongs_to :follower, class_name: "User" belongs_to :followed, class_name: "User" validates :follower_id, presence: true validates :followed_id, presence: true end </code></pre> <p>INVITATION</p> <pre><code>class Invitation &lt; ActiveRecord::Base attr_accessible :recipient_email, :sender_id, :sent_at, :token belongs_to :sender, :class_name =&gt; "User" VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i before_create :generate_token private def generate_token self.token = Digest::SHA1.hexdigest([Time.now, rand].join) end end </code></pre> <p><strong>SCHEMA</strong></p> <pre><code>create_table "users", :force =&gt; true do |t| t.string "name" t.string "email" t.integer "invitation_id" t.integer "invitation_limit" t.boolean "admin", :default =&gt; false #----------HERE!! t.timestamp "created_at", :null =&gt; false t.timestamp "updated_at", :null =&gt; false t.string "password_reset_token" t.timestamp "password_reset_sent_at" end create_table "invitations", :force =&gt; true do |t| t.integer "sender_id" t.string "recipient_email" t.string "token" t.datetime "sent_at" t.datetime "created_at", :null =&gt; false t.datetime "updated_at", :null =&gt; false end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload