On 10 February 2011 09:37, Mauro <[email protected]> wrote:
> On 10 February 2011 09:31, Colin Law <[email protected]> wrote:
>> On 9 February 2011 11:12, Mauro <[email protected]> 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?

Do you mean test whether it is saved ok in the create action?  You
know whether it saved ok by the path it took through the action.

Colin

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to