marcoroth / turbo_power-rails

Power-pack for Turbo Streams

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

make helpers available in controller

chmich opened this issue · comments

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

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

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