Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8851907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:16:17+00:00 2026-06-14T13:16:17+00:00

All my code is working nicely, I want to render the same page :new

  • 0

All my code is working nicely, I want to render the same page :new after a user submits a form with your order. The problem is about the :notice message that I want to display Pedido enviado com sucesso. in the page after a submission but it doesn’t work. My validation error messages are displayed nicely but I don’t know why my success message doesn’t.

Any tips?

(Sorry about my code indentation)

My pedidos_controller goes down:

class PedidosController < ApplicationController

  def new
    @pedido = Pedido.new
    1.times do
      pessoa = @pedido.build_pessoa
      produto = @pedido.produtos.build
  end

  respond_to do |format|
    format.html # new.html.erb
    format.json { render json: @pedido }
  end
end

def create
  @pedido = Pedido.new(params[:pedido])
  respond_to do |format|
    if @pedido.save
      PedidosMailer.delay.registro_do_pedido(@pedido)
      PedidosMailer.delay.email_para_cotar_produtos(@pedido)
      format.html { redirect_to action: "new", notice: 'Pedido enviado com sucesso.' }
      format.json { render json: @pedido, status: :created, location: @pedido }
    else
      format.html { render action: "new" }
      format.json { render json: @pedido.errors, status: :unprocessable_entity }
    end
  end
end
end

my new.html.erb view:

<p id="notice"><%= notice %></p>
<%= render 'form' %>

my _form.html.erb view:

<%= form_for(@pedido, :html => { :class => "form-contato"}) do |f| %>
<% if @pedido.errors.any? %>
  <div id="error_explanation">
    <h2>Ocorreram <%= pluralize(@pedido.errors.count, "erro") %></h2>

  <ul>
  <% @pedido.errors.full_messages.each do |msg| %>
    <li><%= msg %></li>
  <% end %>
  </ul>
</div>
<% end %>

<div class="row">
  <div class="span4">
    <h1>Dados pessoais</h1>
    <%= f.fields_for :pessoa do |builder| %>
      <%= render 'pessoa_fields', f: builder %>
    <% end %>
  </div>

<div class="span8">
  <h1>Ítens</h1>

  <%= f.fields_for :produtos do |builder| %>
    <%= render 'produto_fields', f: builder %>
  <% end %>
</div>
<div class="span10">
  <%= link_to_add_fields "Adicionar mais produtos", f, :produtos %>
</div>
  <%= button_tag "Enviar", class: "btn btn-red span10", name: "commit" %>
</div>
<% end %>

my _pessoa_fields.html.erb view:

<fieldset>
<%= f.text_field :nome, class: "span4", placeholder: "Nome" %>
<br />
<%= f.text_field :telefone, class: "span4", placeholder: "Telefone" %>
<br />
<%= f.text_field :email, class: "span4", placeholder: "Email" %>
</fieldset>

my _produto_fields.html.erb view:

<% @lista_de_produtos = ["Qualibom standard", "Qualibom premium", "Bomdemais standard", "Bomdemais premium"] %>
<fieldset class="campos-produtos span10">
<div class="span3">
    <%= f.select :nome, options_for_select(@lista_de_produtos, :selected => f.object.nome), :prompt => 'Selecione um produto' %>
</div>
<div class="span3">
    <%= f.text_field :quantidade, class: "span3", placeholder: "Quantidade" %>
</div>
</fieldset>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:16:18+00:00Added an answer on June 14, 2026 at 1:16 pm

    You need to use flash[:notice], not notice, in your view:

    <% if flash[:notice] %>
      <p id="notice"><%= flash[:notice] %></p>
    <% end %>
    

    When you pass a message via the notice: parameter of redirect_to, it’s placed into the flash array, which is a special pseduo-session which persist for a single request:

    From the ActionController::Redirecting documentation:

    It is also possible to assign a flash message as part of the redirection. There are two special accessors for the commonly used flash names alert and notice as well as a general purpose flash bucket.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to MVC. I've got this all working nicely except when the page
I have following code working nicely on all browsers but IE 7... <script type=text/javascript>
I'm writing a PDF file directly from code, it's all working nicely, but I
Hey all i am in need of some help getting my code working correctly
Trying to post JSON data to Spring controller.. Not working at all JSP Code:
The code below is working. It will progress through all columns in the sheet
I have looked all over and cannot figure out why this code isn't working.
I have a pretty typical bookmarklet code that's working perfectly for me in all
I've been working with somebody else's code and noticed that on all uses of
I've got the following snippet of code and its all working, and bringing in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.