Wednesday, 11 September 2013

Instance Variable string collection lost after render => 'new'

Instance Variable string collection lost after render => 'new'

When I get an error creating a quote, it renders the same page it was just
on and displays the errors. Unfortunately two inputs are drop down menus
of strings, and they disappear when the refresh happens.
I've looked at Rail 3: instance variable not available after redirection
which talks about sessions, which looks like it could be the right way to
go but I'm not sure. Any help would be appreciated.
quotes controller
def new
@quote = Quote.new
@quote.items.build
@types = ["T-Shirt", "Hoodie", "Sweatpants"]
@colors = ["White", "Black", "Red", "Blue", "Green"]
end
def create
@quote = Quote.new(params[:quote])
respond_to do |format|
if @quote.save
format.html { redirect_to root_url }
flash[:success] = "Your quote is being approved. You will recieve an
email shortly!"
format.json { render json: @quote, status: :created, location: @quote }
else
format.html { render :action => 'new' }
format.json { render :json => @quote.errors, :status =>
:unprocessable_entry }
flash[:error] = "Quote failed to create! Try again!"
end
end
end
form partial
<!-- item form -->
<%= f.input :make, collection: @types, label: 'Thread Type' %>
<%= f.input :amount, label: 'How Many' %>
<%= f.input :color, collection: @colors %>
<!-- nested form for creating a design of an item -->
<%= f.simple_fields_for :designs, :html => { :multipart => true } do
|designform| %>
<%= render "customdesign", g: designform %>
<% end %>
<!-- add/remove another design -->
<%= f.link_to_add "Add Design", :designs %>
<%= f.input :note, :input_html => { :cols => 50, :rows => 3 }, label:
'Special Notes or Requests' %>
<%= f.link_to_remove "Remove" %>

No comments:

Post a Comment