```ruby
class VotesController < ApplicationController

  def create
  end

  def update
  end

  def index
    @vote = Vote.new
    @votes = Vote.all
  end

  def find_per_question
  end

  private
  def vote_params
    params.require(:vote).permit!
  end
end
```

Reconfigure Vote controller to be DRY and accept JSON Requests from Vote Backbone model -Rewrite vote_params method to exclude is_upvote (allows for searching if incoming vote already exists without id) -Add upvote_param method that allows for setting of solely the is_upvote attribute -Create a private save_vote method -Create a private set_vote method that will set is_upvote attribute properly -Use save_vote and set_vote method in the update method if logged in -Use set_vote and save_vote method in create method if logged_in after checking if vote by user already exists
user
```ruby
class VotesController < ApplicationController

  def create
    if logged_in
      @vote = Vote.where(user_id: session[:user_id]).find_or_initialize_by(vote_params)
      set_vote
      save_vote
    else
      render json: nil
    end
  end

  def update
    if logged_in
      set_vote
      save_vote
    end
  end

  def index
    @vote = Vote.new
    @votes = Vote.all
  end

  def find_per_question
  end

  private

  def set_vote
    @vote ||= Vote.find(params[:id])
    p upvote_param
    if @vote.is_upvote == upvote_param[:is_upvote]
      @vote.is_upvote = nil
    else
      @vote.is_upvote = upvote_param[:is_upvote]
    end
  end

  def save_vote
    if @vote.save
      render json: @vote.to_json
    else
      render json: nil
    end
  end


  def vote_params
    params.require(:vote).permit(:votable_type, :votable_id)
  end

  def upvote_param
    params.require(:vote).permit(:is_upvote)
  end
end
```
assistant