Here is my situation :
Items :
has_many :games
Users :
has_many :games
Games :
belongs_to :user
belongs_to :item
On my Item page i have a link to create a new game. How to get the item ID in a secure way ? Because in my database I need to store for 1 game the user_id and the item_id. For now, I'm doing this which store only the user_id automatically :
def create
@game = current_user.games.build(game_params)
if @game.save
redirect_to root_url
else
render 'pages/home'
end
end
private
def game_params
params.require(:game).permit(:time, :score)
end
I suppose that adding a game_params :item_id is not the right way and is not secure ?!
Here is the scenario wanted :
A user came to an item page, click on a button to create a game, when I record the game I want to be able to store the user_id (it's OK for this part) and the item_id without any more user interaction. I don't want him to choose "manually" I want to "force it" (thanks to the item page where he comes from)
In a perfect world I would like to :
retrieve every games from one user with something like
current_user.games
retrieve every games from one item with something like
item_id.games