Gustavo Pinedo
Joined
Activity
Guilherme Domingos as you say we need to move to gem x, after installing the gem ( bundle add x ), try this:
// twitter_account.rb
def client
x_credentials = {
api_key: Rails.application.credentials.dig(:twitter, :api_key),
api_key_secret: Rails.application.credentials.dig(:twitter, :api_secret_key),
access_token: token,
access_token_secret: secret,
}
X::Client.new(**x_credentials)
end
// tweet.rb
def publish_to_twitter!
tweet = twitter_account.client.post("tweets", "{\"text\":\"#{body}\"}")
update(tweet_id: tweet["data"]["id"])
end
This works for me, I hope it helps.
Try this:
Open a rails console and run:
Rails.application.credentials.twitter
then, verify the keys you write in the omniauth.rb file has the correct "name" (key in a hash)
I wrongly saved the secret_key in credentials as api_secret_key and that caused the same error you have.
Hope it helps
As Alex says, this is a common way to add some validation (to password in this case), you can even add something like:
validates :password, presence: true, length: {minimum: 6, maximum: 30}
in order to add length validation too, getting responses like "Password is too short (minimum is 6 characters)" when the entered password does not meet this validation.
On the other hand, many user profile forms show password and password confirmation fields, if the user doesn't enter any value on these, the password remains the same, but if other fields have changed, these can be updated on the same action.
Yes, it's a common "rails way" to write an if statement in a single line when possible