title: Using form_for to add a user to Collaboration model
body: <p>I'm building a very basic wiki-style app that uses 3 models: User, Wiki, and Collaboration.  My goal is, via the edit wiki page, a user should be able to add another user to the wiki as a "collaborator".  This is what I have so far: </p>
  
  <h1>Wiki Model</h1>
  
  <pre><code>class Wiki &lt; ActiveRecord::Base
  belongs_to :user
  
  has_many :collaborations
  has_many :collaboration_users, through: :collaborations, :source =&gt; :user 
  
  
  scope :visible_to, -&gt; (user) { user.role == 'admin' || user.role == 'premium' ? all : where(private: false) }
  
  
  
  end
  </code></pre>
  
  <h1>User Model</h1>
  
  <pre><code>class User &lt; ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
  :recoverable, :rememberable, :trackable, :validatable, :confirmable
  
  has_many :wikis
  has_many :collaborations
  has_many :collaboration_wikis, through: :collaborations, :source =&gt; :wiki
  
  after_initialize :set_default_role
  
  def set_default_role
    self.role ||= 'standard'
  end
  
  def upgrade_to_premium
    self.update_attribute(:role, "premium")
  end
  
  def admin?
    role == 'admin'
  end
  
  def standard?
    role == 'standard'
  end
  
  def premium?
    role == 'premium'
  end
  
  end
  </code></pre>
  
  <h1>Collaboration Model</h1>
  
  <pre><code>class Collaboration &lt; ActiveRecord::Base
  belongs_to :user
  belongs_to :wiki
  end
  </code></pre>
  
  <h1>My _form.html.erb</h1>
  
  <pre><code>&lt;%= form_for wiki do |f| %&gt;
   &lt;% if wiki.errors.any? %&gt;
   &lt;div class="alert alert-danger"&gt;
     &lt;h4&gt;There are &lt;%= pluralize(wiki.errors.count, "error") %&gt;.&lt;/h4&gt;
     &lt;ul&gt;
       &lt;% wiki.errors.full_messages.each do |msg| %&gt;
         &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt;
       &lt;% end %&gt;
     &lt;/ul&gt;
   &lt;/div&gt;
   &lt;% end %&gt;
  &lt;%= form_group_tag(wiki.errors[:title]) do %&gt;
  &lt;%= f.label :title %&gt;
  &lt;%= f.text_field :title, class:'form-control', placeholder: "Enter Wiki name" %&gt;
  &lt;% end %&gt; 
    &lt;div class="form-group"&gt;
      &lt;%= f.label :body %&gt;
      &lt;%= f.text_area :body, rows: 8, class:'form-control', placeholder: "Enter Wiki body" %&gt;
    &lt;/div&gt;
  &lt;% if current_user.role == 'premium' || current_user.role == 'admin' %&gt;
      &lt;div class="form-group"&gt;
        &lt;%= f.label :private, class: 'checkbox' do %&gt;
        &lt;%= f.check_box :private %&gt; Private Wiki
        &lt;% end %&gt;
      &lt;/div&gt;
  
  &lt;% end %&gt;
    &lt;%= f.submit "Save", class: 'btn btn-success' %&gt;
    &lt;% end %&gt;
  </code></pre>
  
  <p>My goal is to show a list of all users (if role == premium or admin) with the option to add or delete as a collaborator.  Can someone point me in the right direction?</p>
  
  <p>Thank you!</p>