2

In very short. When I have a form set as POST, the controller picks up the request, processes it and even starts to render the correct view. But the browser stays on the form page

When I switch the form to GET, it works (yes, I remembered to change the route from get to post and back)

Here is the log:

Started POST "/sooth/search" for 127.0.0.1 at 2022-07-02 13:43:40 -0700 Processing by SoothController#search as TURBO_STREAM Parameters: {"authenticity_token"=>"[FILTERED]", "search"=>{"name"=>"search keywords"}, "commit"=>"Save Search"} Rendering layout layouts/application.html.erb Rendering sooth/search.html.erb within layouts/application I am rendering the search html page

The line above is a log message in the search.html.erb page

Rendered sooth/search.html.erb within layouts/application (Duration: 1.0ms | Allocations: 148) Rendered layout layouts/application.html.erb (Duration: 6.6ms | Allocations: 2710) Completed 200 OK in 15ms (Views: 11.3ms | ActiveRecord: 0.0ms | Allocations: 4040)

BUT the search page is not displayed. Browser stays on the search form page.

Any hints deeply appreciated. (And as you have probably guessed, I am day 1 with rails)

EDIT:

class SoothController < ApplicationController
  include SoothHelper

  def index
    puts "sooth index"
    template = get_query_template('sooth_search')
    puts(template)
  end

  def search

    form_params = params[:search]
    puts 'searching' + form_params[:name].to_s
    render "sooth/search"
  end

end

ROUTES

Rails.application.routes.draw do
  Rails.application.routes.draw do
    get "/nlp_data", to: "nlp_data#index"
    get "/sooth", to: "sooth#index"
    post "/sooth/search", to: "sooth#search"

end
7
  • 1
    can you share the controller file? Commented Jul 2, 2022 at 20:55
  • shared. deeply appreciate your attention Commented Jul 2, 2022 at 22:19
  • Do you get any error in the browser console ? Commented Jul 3, 2022 at 0:52
  • 1
    i'm not very familiar with rails 7 but in the request it says Turbo Stream. did you send the request as async if that so perhaps that is the cause of the problem Commented Jul 3, 2022 at 10:34
  • 1
    in rails 7 all your redirects need a status to work, like :unproccesable_entity, because turbo_drive usses statuses to know how to handle redirects, but the ok stus is the default status Commented Jul 4, 2022 at 9:10

1 Answer 1

1

Your problem is you are trying to render the same page instead of redirecting to to the sooth page ,and secondly you cannot acces params directly in a post request, instead you must acces it from a strong param method

class SoothController < ApplicationController
  include SoothHelper

  def index
    puts "sooth index"
    template = get_query_template('sooth_search')
    puts(template)
  end

  def search

    form_params = sooth_params[:search]
    puts 'searching' + form_params[:name].to_s
    redirect_to "/sooth"
  end

  private 
  def sooth_params
   params.require(:sooth).permit(:search)
  end

end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.