Hide a view after successfully creating an entry

Hi - brand new to rails - using rails 7.1.3.2 I am on my first learning project used the rails g scaffold etc and after I successfully created an entry it takes me to a page which shows the entry and edit, back to and destroy functionality. What I would like is to make an entry and for not to be taken to the page as mentioned. I simply want to make an entry to the database and then taken back to the page where I could make another entry if desired. I don’t want to edit, and destroy and show any entries made. Any help much apreciated Regards

Easy peasy. Simply change the redirect_to destination in your controller’s create method.

Hi - thanks for this. Could you explain which part of my code needs changing please.

def create @gotit = Gotit.new(gotit_params)

respond_to do |format|
  if @gotit.save
    format.html { redirect_to gotit_url(@gotit), notice: "Gotit was successfully created." }
    format.json { render :show, status: :created, location: @gotit }
  else
    format.html { render :new, status: :unprocessable_entity }
    format.json { render json: @gotit.errors, status: :unprocessable_entity }
  end
end

end

Assuming the page for a new Gotit is given by new_gotit_url:

def create
  @gotit = Gotit.new(gotit_params)
  respond_to do |format|
    if @gotit.save
      format.html { redirect_to new_gotit_url, notice: "Gotit was successfully created." }
      format.json { render :show, status: :created, location: @gotit }
    else
      format.html { render :new, status: :unprocessable_entity }
      format.json { render json: @gotit.errors, status: :unprocessable_entity }
    end
  end
end

If not, just use the appropriate helper. I know some sites redirect back to an index of the resource, so gotits_url is another possibility. In any case, use the url helper that takes you to the page where you create new gotits

Thanks - that now works fine.