0

In the application, when creating a feature, it was necessary to add hotwired/turbo-rails.

// app/javascript/application.js import "@hotwired/turbo-rails" import "controllers" import "trix" import "@rails/actiontext" 
//config/importmap.rb # Pin npm packages by running ./bin/importmap pin "application", preload: true pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true pin_all_from "app/javascript/controllers", under: "controllers" pin "trix" pin "@rails/actiontext", to: "actiontext.js" 

However, it caused a problem with redirections that I did not understand.

I have controller:

class Cats::ReservationsController < ApplicationController def create @cat = Cat.find(params[:reservation][:cat_id]) @reservation = @cat.build_reservation(reservation_params) if @reservation.save @cat.update(status: :reservation_reported) redirect_to root_path # HERE IS PROBLEM else # respond_to do |format| # format.turbo_stream do # turbo_stream.replace 'cats_reservations_form', Kittens::Reservations::ReservationComponent.new(cat: @cat, reservation: @reservation) # end # format.html { render Kittens::Reservations::ReservationComponent.new(cat: @cat, reservation: @reservation) } end end end 

viewComponent app/components/kittens/reservations/reservation_component.html.haml:

= form_with(model: @reservation, local: true) do |form| = form.label :start_date = form.datetime_field :start_date = form.hidden_field :cat_id, value: @cat.id -# %span Na emeila dostaniesz numer konta do wplaty zalicznki = form.submit 'Send Request' 

My problem: Before Send Request/action create:

before

After click send request/ action create:

after

Next clicks:

next clicks

next clicks2

I can do something like that:

// app/javascript/application.js // import "@hotwired/turbo-rails" import "controllers" import "trix" import "@rails/actiontext" 

and then redirect_to root_path its work corectly, but I need turbo in other controller.

Any hints?

4
  • looks like you don't wish to take advantage of any turbo features, so disable turbo for this form. data-turbo=false Commented Jul 7, 2024 at 22:52
  • Yes: if I add data: { turbo: false } to form: = form_with(model: @reservation, local: true, data: { turbo: false }) do |form| turbo will be disabled in the controller. Commented Jul 8, 2024 at 0:04
  • so does the redirect succeed with turbo disabled? Commented Jul 8, 2024 at 0:15
  • For this particular case indicated, it is approx. However, as I see, there are more problems in the application: For example: Action : = link_to 'Sign out', destroy_user_session_path, method: :delete, data: { confirm: 'Are you sure?' } or ``` = link_to 'Sign out', destroy_user_session_path, method: :delete, data: {turbo: false, confirm: 'Are you sure?' } ``` and the view is duplicated again when I click. ''' Can't add screenshot ''' Commented Jul 8, 2024 at 22:01

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.