Vincent Robert


260 Experience
2 Lessons Completed
0 Questions Solved


Posted in How to use Devise with Hotwire & Turbo.js Discussion

Has anyone managed to use the "current_user" method from Devise in broadcasted partial views?

I have merged the 2 applications "hotwire-devise" & "hotwire-twitter-clone",
and when I add a call to current_user
(like for instance <%= link_to "Edit", edit_tweet_path(tweet) if current_user.present? %> in the _tweet.html.erb file),
I get an error because the method is not available in this context:

Started POST "/tweets" for at 2021-01-29 14:45:53 +0100
Processing by TweetsController#create as TURBO_STREAM
Parameters: {"authenticity_token"=>"[FILTERED]", "tweet"=>{"body"=>"TEST"}, "commit"=>"Create Tweet"}
Tweet Create (0.8ms)  INSERT INTO "tweets" ("body", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id"  [["body", "TEST 003"], ["created_at", "2021-01-29 13:45:53.776383"], ["updated_at", "2021-01-29 13:45:53.776383"]]
Rendered tweets/_tweet.html.erb (Duration: 4.3ms | Allocations: 2000)
Completed 500 Internal Server Error in 30ms (ActiveRecord: 19.6ms | Allocations: 5713)

ActionView::Template::Error (Devise could not find the `Warden::Proxy` instance on your request environment.
Make sure that your application is loading Devise and Warden as expected and that the `Warden::Manager` middleware is present in your middleware stack.
If you are seeing this on one of your tests, ensure that your tests are either executing the Rails middleware stack or that your tests are using the `Devise::Test::ControllerHelpers` module to inject the `request.env['warden']` object for you.):
 6:       <%= button_to "Likes (#{tweet.likes_count})", tweet_like_path(tweet), method: :post %>
 7:       <%= button_to "Retweets (#{tweet.retweets_count})", tweet_retweet_path(tweet), method: :post %>
 9:       <%= link_to "Edit", edit_tweet_path(tweet) if current_user.present? %>
10:     </div>
11:   </div>
12: <% end %>

Hi Chris.
Would it be possible to add a feature on GoRails in order to manually "mark as watched" an episode?
When I randomly select an episode to watch, I would like to list only those that I have not watched yet.
Thank you for your work.

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

© 2023 GoRails, LLC. All rights reserved.