Prevent User from committing to the same event twice
<p>I currently have a User model and a Event model. Right now a the current user can "commit" to an event. The method basically pushes the event on the user if they click the button_tag. I'm trying to figure out how to prevent a user from committing the same event twice. Is there a simple check that I'm unaware of??</p>

<h2>Controller</h2>

<pre><code>  class EventsController &lt; ApplicationController
  before_action :authenticate_user!

  def index
    @event = Event.all
  end

  def commit
    @event = Event.find(params[:id])
    current_user.events &lt;&lt; @event
    redirect_to root_path
    flash[:success] = "You have successfully commited to this event!"
  end
end
</code></pre>

<h2>Form</h2>

<pre><code> &lt;% @event.each do |event| %&gt;
  &lt;h3&gt;
    &lt;%= event.name %&gt;
  &lt;/h3&gt;
  &lt;p&gt;
    &lt;%= event.description %&gt;
  &lt;/p&gt;
  &lt;%= button_to "Commit", commit_event_path(event.id)  %&gt;
&lt;% end %&gt;
</code></pre>

<h2>Event Model</h2>

<pre><code>class Event &lt; ActiveRecord::Base
  has_and_belongs_to_many :users
  geocoded_by :address
  after_validation :geocode
  validates :name, presence: true
  validates :description, presence: true
  validates :full_street_address, presence: true
  validates :city, presence: true
  validates :zip, presence: true
  validates :state, presence: true

  def address
    [city, state, zip, full_street_address].compact.join(', ')
  end
end
</code></pre>

<h2>User Model</h2>

<pre><code>class User &lt; ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable, :confirmable,
         :recoverable, :rememberable, :trackable, :validatable

  has_and_belongs_to_many :events 
end
</code></pre>