Ask A Question

Notifications

You’re not receiving notifications from this thread.

How to use Hotwire in Rails Discussion

Has anyones destroy action for an object stopped working? And when clicked, it redirects to the show page without destroying the object?

Reply

Try a button_to instead of a link_to (still using method: :delete)

Reply

Thanks Bryce! - I managed to get link_to working after re-adding rails@ujs. Button_to also works too.

Reply

Thanks Bryce, button_to works perfectly!

Reply

Hotwire is amazing. I tired different mini-apps to using Hotwire feature. While I know I can edit a form, could i edit an attribute (such as an email) on its own without editing/submitting the whole form?

Reply

You probably have to create a separate controller to handle the editing/updating of that attribute and then wrap that attribute in hotwired form. Or use regular CRUD controller but still wrap each field in a separate form. Or do some javascripting.

Reply

Hi guys, has anyone tried broadcasting from a model (or a background Active Job worker, in my case using Shoryuken) for a resource that is nested.

broadcast_replace_to is complaining about /project/:project_id/files/:id missing keys (e.g. project_id) for the resources show route

Reply

solved: my issue was a link_to in the partial being rendered by broadcast_replace_to
Chris spotted my issue right away, i switched the offending instance variables to locals - all working super well now.

Reply

rails s crashes and throws this error "Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED) (Redis::CannotConnectError)" after I add the turbo_stream_from. Only way I'm able to get it to run is by running redis-server in a separate command line. Is this intended? Anyway around it?

Reply

The gem foreman will help you here. It helps get your multiple processes started in one command

Reply

I have a datepicker in my form, and it's broken when the form is replaced. How to solve that issue?

Reply

It seems that upgrading past turbo-rails version 0.5.3 is an issue. Using tips from this episode, form submission is now submitting as html again instead of TURBO_STREAM. This causes an issue when create needs to re-render on save failure as seen in this path - https://github.com/gorails-screencasts/hotwire-twitter-clone/blob/master/app/controllers/tweets_controller.rb#L35

Anyone else have issues when using turbo-rails 0.5.4 and up? The change seems to be around this commit https://github.com/hotwired/turbo-rails/commit/b3fab95cc3e73b1a2960f0ea4a3509e0d490a16a#diff-a6c9ea9b91a99345ff04b9597b41369bc2552724c7c00135db376ff782aaf7ab

Reply

I ended up having to update my test project to only use loading of turbo-rails through the tag helper...after I did that it worked as it did before https://gitlab.com/doug.stull/turbo_modal/-/commit/ce17a5208fb175f3ffe8c5e40ed4031f18ca9f08

Reply

I had the same issue - updated to turbo-rails 0.5.9 and links / forms stopped submitting as turbo_streams. Moved back to 0.5.3 and it went back to normal. Wtf! Thanks for pointing me to the heart of the issue though!

Reply

I have an issue when I submit an empty for the second time. If I submit the empty field for the first time, the validation displays, then if I submit again with empty field, the submit button is then disabled. How to solve that?

Reply

When I cloned this from GitHub I was pleasantly surprised to not see webpacker or Node.Js stuff, the project folder for this Hotwire project is around 13MB rather than 124MB for a new Rails 6 project.

Can anybody tell me how to setup a new Rails 6 project using Hotwire WITHOUT Webpacker and Node.js?

Reply

You can pass in 'Rails new my_app --skip-webpack-install' to create the app framework and skip Webpacker altogether.

Reply

I saw that suggestion by "chrisma" on a Stack Overflow answer https://stackoverflow.com/questions/64466331/is-it-possible-advisable-to-run-rails-6-without-webpacker but it seems to still have some webpack bits around. Do I just have to accept this and delete them manually?

Reply

You can safely delete the files if you are not going to use Webpacker at all.

Reply

Has anyone been able to get hotwire to work with authorization when adding/updating data on an index page. For example if I have an index page with a table and each row on the table has an Edit button on it which is wrapped in a pundit policy check.

Reply

Check this out: https://blog.cloud66.com/making-hotwire-and-devise-play-nicely-with-viewcomponents/

I realize this example is using devise and you mentioned Pundit, but I think it might at least send you down the right path. Hope it helps!

Reply

How to add auto scrolling when adding a post?

Reply

Have you noticed that every time you click 'Cancel' from edit, it results in a new nested turbo_frame_tag with the same dom id? It doesn't seem to break anything and it's obvious why it's happening, but it still seems weird to me. I was trying to avoid the same behavior in my own project, but things got messy quickly. I can't figure out how you would call 'show' without the corresponding turbo_frame_tag.

Edit for visual: https://paste.pics/de3344e3cf09a81522d992b37f6edb80
Edit part 2: To be super clear, the above image is of this project, not mine.

Reply

Can't tell you why it's happening, I looked at the code and it seems ok. Nothing wrong with.

I suspect the whole concept of turbo_frame_tags is a bit confusing to many. We're not used to the idea of navigation within a frame, it sort of remind me of how iframes work.

Maybe there is confusion with how turbo_streams should work with turbo_frames.

Reply

I hear you. I think iframes were a little more intuitive because the most complicated operation involved targeting in and out of them.

With the cancel link here, it's a bit tricky--for me, anyway--because unlike the CRUD operations, which you can broadcast to from the model (as was done here), what should be a straightforward operation seems to have no real recourse to things like turbo_stream.replace. Calling 'show' means invoking that turbo_frame_tag, whether you want it or not. You could render a partial without it, but then you lose the Turbo functionality for the next operation.

It's probably a conceptual problem, but for me the rather austere docs don't do a great job of wedding streams and frames (to say nothing of linking them with Stimulus).

Reply

Hi Chris, any solution to nested HTML's ? or is it the way it works ? Pls explain. Looks confusing.

Reply

I have to the best of my ability followed the code - but for some reason, the only two things that don't broadcast is the like and retweet updates. Can anyone else verify this is the case?

Reply

Tried to implement it with a user model & devise. Devise is working ok but on error on creating an user the form is rendered ok, second time when I’m trying to resubmit with an error the user is not passed and on inspection the turbo frame is empty? What might be the issue?

Reply

solved it, I had it misconfigured

Reply

I can't get any of my delete links to work, has this happened to anyone else?

Reply

You using link_to or button_to ?

Reply

Hi, I was trying that also, I think I was able to make it work:

on _tweet.html.erb I added

 <%= link_to "Delete", tweet_path(tweet), method: :delete, data: { turbo_method: "delete" } %>

on tweets_controller:

format.turbo_stream { render turbo_stream: turbo_stream.replace(@tweet, partial: "tweets/form", locals: { tweet: @tweet}) }

Not sure if is the correct way to make it work, but worked for me.

Reply

It seems strange to me that Turbo has the same problem out of the box that Turbolinks has when it comes to validation errors.

Reply

hi chris , i'm trying to implement comment feature without refresh in my rails app using hotwire , but when i run the server , i find this error : Sprockets::Rails::Helper::AssetNotFound in Posts#index , The asset "importmap.json" is not present in the asset pipeline. (Extracted source (around line #16): <%= stimulus_include_tags %>

Reply

How do you unit test hotwire? only system tests with capybara? i wonder if we can easily unit test it with request specs?

Reply

BTW, were you guys using this with Rails 7?

Reply

i am planning to use Rails7 in my new project that i will start in few days

Reply

Awesome!

I think this tutorial's a little outdated. Was trying to do it with Rails 7, and some things are configured differently.

Reply

Excellent stuff!

Reply

How to get the likes and retweets counter updated? When opening two separate tabs it is the only one that is not reflected in both

Reply

To whom it may concern, make sure your redis-server is running and the you update the development adapter to redis with the URL in cable.yml if turbo is not working as expected. Thanks for the lesson Chris!

Reply
Join the discussion
Create an account Log in

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

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

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