Haven't looked recently regarding new gems that might feature what you want, but if you don't mind building your own, I suggest implementing it RESTful.
Start by adding a model
class SelectedMood < ActiveRecord::Base
# has the following attributes
# session_id:string:index
# mood_id:integer
validates :session_id, uniqueness: true
end
Then each of your mood will be a button (you may want transparent buttons) having the following:
<%= button_to selected_moods_path(selected_mood: {mood_id: CHANGE_MOOD_ID_HERE, session_id: session.id}), remote: true, method: :post do %>
<%= image_tag 'mood1.png' %>
<% end %>
Then the buttons will be a POST to a create
method of your SelectedMoodsController
class SelectedMoodsController < ApplicationController
def create
@selected_mood = SelectedMood.new(selected_mood_params)
@selected_mood.save
render js: "alert('Thanks for selecting a mood!');"
end
def selected_mood_params
params.require(:selected_mood).permit(:session_id, :mood_id)
end
end
I used save!
above instead of the normal save
intentionally.
The implementation above still is missing error-handling and reporting, but you should have an idea now on where to start.
You may or may not want a separate Mood
model for all mood options.
As for the IP address, it is not very accurate to have uniqueness validation because if you're browsing through a phone over 3G, all of the phones connected will share the same IP, as it is the cellular tower's IP which has the one single public IP, and our phones just have different internal IP. For sessions, it is also still not very accurate because one can do multiple incognito browser sessions just to spam-click on a mood, because all of these incognito sessions have different sessions.