DEV Community

Discussion on: Form validation in Rails

Collapse
 
vulcanobr profile image
Marcelo Severo • Edited

Good afternoon, congratulations for the post, I'm a beginner in Rails, I reproduced your example but I'm not able to generate the rails messages in the view; json render appears; but when I remove the json nothing happens; what do I need to change in your example? do I need to install the stimulus ( rails webpacker:install: stimulus) ?

Collapse
 
ryanb1303 profile image
Ryan B

if the json you remove is in the users_controller that you remove, you need to add new error renderer. like this example generated from rails g scaffold

 respond_to do |format|
      if user.save(user_params)
        format.html { redirect_to users_path, success: "Success " }
        format.json { render :show, status: :ok, location: @gender }
      else
        format.html { render :edit, status: :unprocessable_entity }
        format.json { render json: user.errors, status: :unprocessable_entity }
      end
 end
Enter fullscreen mode Exit fullscreen mode