Question:
I need to create an object from just a button.
I don't pass anything to the method, I just call it through the button.
All the data I need I have access to in the controller action I'm using.
But I can't insert it in the database, because of Strong Parameters.
I've tried so much solution that I don't even know what I'm doing anymore. :/
Here I try to create a new token with the data I generated in the action
@token = Token.new(duration: duration, token: token, check: false, user_id: current_user.id)
This is the strong parameters part.
def token_params
params.require(:token).permit(:duration, :token, :check, :user_id, :gym_id)
end
And when I check the parameters I passed to the action. Ex.: {"utf8"=>"✓" …. } Hash "token" doesn't come with it, maybe that's obvious since I'm not sending anything besides the button commit.
Answer:
You really don't need strong params in this case. I believe that just changing new
to create
will solve your problem in your action
.