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.
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!!
When I do User.last.twitter_accounts, I get this:
=> #]>
Why are the name and username nil?
Any advice is hugely appreciated :)
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`
Hello geeks
Can someone help me with this episode? I am getting this error. I am new
undefined method `twitter_accounts' for #
Hey I keep getting routing error using omniauth 2.1.1
No route matches [GET] "/auth/twitter"
solved it link_to on index.html.erb has to be button.to for the route to be found by omniauth 2.1.1
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" %>