On 10 February 2011 09:31, Colin Law <clan...@googlemail.com> wrote:
> On 9 February 2011 11:12, Mauro <mrsan...@gmail.com> wrote:
>> L'action create of deliveries controller is:
>>
>> def create
>>   @customer=Customer.find(params[:customer_id])
>>   @delivery = @customer.deliveries.build(params[:delivery])
>>   @document = @customer.build_document(params[:document])
>>   if @delivery.valid? and @document.valid?
>>     Delivery.transaction do
>>       @delivery.save!
>>       @document.save!
>>     end
>>     flash[:success] = 'Ok'
>>     respond_with(@customer)
>>   else
>>     @products = Product.all
>>     render 'customers/show', :layout => 'delivery'
>>   end
>>  end
>>
>> l'action show of customers controller is:
>>
>> .............
>> <% content_for :delivery_form do %>
>>  <%= render 'deliveries/form' %>
>> <% end %>
>> <% content_for :delivered do %>
>>  <%= render 'delivered/form' %>
>> <% end %>
>>
>> I want to see only one of the two content_for depending on @delivery
>> and @document are saved or not.
>> I have a form, on submit @delivery and @document are created, if they
>> are not valid I have to see the show view and in the layout I should
>> see <%= yield :delivery_form %> while if the objects are valid eand
>> then saved in the database in the layout I should see <%= yield
>> :delivered %>.
>> Based on what I can make the selection?
>
> You could set an @variable in the controller action and test this in
> the view to decide what to show.

Can't I test if an object is saved or not in the database?

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to