All threads / Rails for Beginners Part 27: Twitter Accounts Page Discussion
Ask A Question

Notifications

You鈥檙e not receiving notifications from this thread.

Rails for Beginners Part 27: Twitter Accounts Page Discussion

This episode has been updated for Omniauth 2.0. 馃憤

Many thanks I have this doubt in episode 25 and now I know how to solve it, thanks.

Reply

How do you authorize the user to access my account all the time?
I have to authorize the user every time I log in to twitter.
Any answers are welcome!!

Nvm. Solved this using auth 1.0a

Reply

When I do User.last.twitter_accounts, I get this:
=> #]>
Why are the name and username nil?
Any advice is hugely appreciated :)

<ActiveRecord::Associations::CollectionProxy [#<TwitterAccount id: 1, user_id: 3, name: nil, username: nil, image: nil, token: [FILTERED]
I get this result by the way

I had the same issue. You need to request Elevated access for the Twitter API via the developer dashboard

Reply

On Rails 7 - to get my "Connect a Twitter Account" button to work correctly, I needed to use the following:

<%= button_to "Connect a Twitter account", "/auth/twitter/", method: :post, :data => { turbo: "false" }, class: "btn btn-primary"%>

I also noticed that on my Disconnect button, the confirm "Are you sure?", would not show. I'm guessing it has to do with the button_to and turbo_confirm or something? If anyone figures this out, would love a reply.

For the disconnect button on Rails 7, I used this and it's working correctly with the confirm now. Hope it helps!

<%= link_to "Disconnect", twitter_account, data: { turbo_method: :delete, turbo_confirm: 'Are you sure?' }, class: "btn btn-danger" %>

Got it to work using this
<%= button_to "Disconnect", twitter_account, method: :delete, form: { data: { turbo_confirm: 'Are you sure?' } }, class:"btn btn-outline-danger" %>. Source is stackoverflow but unfortunately links cannot be added to the comment section so will just copy over the explanation.

`Because you are using Turbo, you need to add the data-turbo-confirm to the form itself, unlike in rails-ujs. Which you would add it to the button.

Keep in mind button_to generated a form unlike link_to`

Thanks so much Alex. You really saved me a lot of time.

Reply
Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 62,791+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2022 GoRails, LLC. All rights reserved.