Create an object with strong parameters in Ruby on Rails

3

I need to create an object from just a button.

I do not pass anything to the method, I just call it through the button.

All the data I need to access the controller action I'm using.

But I can not insert into the database, because of Strong Parameters.

I've tried so much solution that I do not even know what I'm doing anymore. :

Here I try to create a new token the data I generated in the action

@token = Token.new(duration: duration, token: token, check: false, user_id: current_user.id)

This is the part of the strong parameters

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" => "✓" ....} The "token" hash does not come together, maybe this is obvious because I'm not sending anything other than the commit button.

    
asked by anonymous 31.10.2016 / 07:53

1 answer

0

You really will not need strong params in this case. I believe that just changing new to create will solve your problem in your action .

    
31.10.2016 / 13:18