0

I have a simple messaging app. Users can set up a public profile with their description and people can send them inquiries. Those inquiries are then collected in a table in the user dashboard.

When a user is clicking on a row, a turbo frame opens up and shows the inquiry.

I would like to implement, that the inquiry is automatically set to @inquriy.seen = true whenever a row is clicked / the inquiry show action is called. Within the table is a blue dot in my ui that indicates, that the message/inquiry is not yet read.

currently i have this code within the show action:

respond_to do |format|
   if @inquiry.update!(seen: true) 
      format.html
      format.turbo_stream { flash.now[:notice] = "Anfrage angesehen." }
   end 
end 

The problem is, that it does not work. The inquiry is successfully updated, but the table does not change. Instead I am getting a Completed 406 Not Acceptable response and an ActionController::UnknownFormat error.

I already tried to accept turbo_streams in the mime_type.rb but there are other features in my app that are using turbo streams that work just fine (btw also in the update action of the inquiries (you can manually set them to read)).

How can I trigger the turbo_stream when clicking calling the show action to update the table in the index action?

Thanks!

  • `if @inquiry.update!(seen: true)` is kind of strange. If you're using `update!` its because you don't expect it to fail and if it does fail it will raise an `ActiveRecord::RecordInvalid` error that must be rescued instead. – max Jan 05 '23 at 16:19
  • Beyond that I'm confused about whats actually going on here - could it be that `update!` is returning false and for some unknown reason not raising? That would lead to `ActionController::UnknownFormat` since `format.turbo_stream` would never be reached. Could it be that the code here isn't actually running at all? An excerpt from the rails logs would be really helpful. – max Jan 05 '23 at 16:24
  • Hey Max, thanks for the response! The update is performing correctly actually. Just the turbo stream is not running. I will provide more information when im at home :) – GabrielTheCoder Jan 06 '23 at 19:47

0 Answers0