Create an object with strong Ruby on Rails parameters

Asked

Viewed 157 times

3

I need to create an object from only one button.

I pass nothing to the method, I call only through the button.

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

But I can not enter in the database, on account of Strong Parameters.

I’ve tried so many solutions I don’t 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 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"=>" .... } The "token" hash doesn’t come together, so maybe it’s obvious because I’m not sending anything, other than the button commit.

1 answer

0


You really won’t need to stop Strong in this case. I believe only changing the new to the create will solve your problem in your action.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.