Ask A Question

Notifications

You’re not receiving notifications from this thread.

Rails for Beginners Part 27: Twitter Accounts Page Discussion

This episode has been updated for Omniauth 2.0. πŸ‘

Reply

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!!

Reply

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 :)

Reply

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

Reply

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

Reply

Thanks a ton! Will try this

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.

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" %>
Reply

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.

Reply

`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`

Reply

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

Reply

Hello geeks
Can someone help me with this episode? I am getting this error. I am new
undefined method `twitter_accounts' for #

Reply

Hey I keep getting routing error using omniauth 2.1.1

No route matches [GET] "/auth/twitter"

Reply

solved it link_to on index.html.erb has to be button.to for the route to be found by omniauth 2.1.1

Reply

For all of us thing to find out why we won't get that popup confirmation,
try adding this at the beginning of index.html.erb:
<%= javascript_include_tag "turbo", type: "module" %>

and change the button code to this:
<%= button_to "Disconnect", twitter_account, method: :delete, data: { turbo_confirm: "Are you sure?" }, class: "btn btn-outline-danger" %>

Reply

That will break the Connect Twitter button so you would also need to replace it with (as Alex Lutz noticed earlier):
<%= button_to "Connect Twitter", "/auth/twitter", method: :post, data: { turbo: "false" }, class: "btn btn-primary" %>

Reply
Join the discussion
Create an account Log in

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

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

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