marcoroth / turbo_power-rails

Power-pack for Turbo Streams
MIT License
277 stars 9 forks source link

make helpers available in controller #19

Closed chmich closed 1 year ago

chmich commented 1 year ago

Thanks for this really helpful gem

currently my view looks anything like that:

= turbo_stream_flash
- if status_success
  = turbo_stream.redirect_to( admin_responsibilities_path, "advance")
- else
  = turbo_stream.replace 'responsibility-form' do
    = render 'form'

Would it be possible to make theese helpers available or some of that available in controller? Or, at least some of them, like the redirect_to

this should, on rendering, adding the tag to the view, so, that turbo can handle the redirect.

this would simplyfiy CRUD actions like that:

  def create
    @responsibility = Responsibility.new(responsibility_params)
    if @responsibility.save
      turbo_stream.redirect_to(admin_responsibilities_path, "advance")
    else
      render status: :unprocessable_entity
    end
  end
marcoroth commented 1 year ago

Hey @chmich, thanks for opening this issue!

You should be able to do something like this:

def create
  @responsibility = Responsibility.new(responsibility_params)
  if @responsibility.save
    render turbo_stream: turbo_stream.redirect_to(admin_responsibilities_path, "advance")
  else
    render status: :unprocessable_entity
  end
end
chmich commented 1 year ago

Thanks @marcoroth for the quick response! it works fine.