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:
After click send request/ action create:
Next clicks:
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?
data-turbo=falsedata: { turbo: false }to form:= form_with(model: @reservation, local: true, data: { turbo: false }) do |form|turbo will be disabled in the controller.= 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 '''