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 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 9 February 2011 11:12, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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? >Any advice? May be there is something wrong? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 9 February 2011 11:12, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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. 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 10 February 2011 09:31, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 9 February 2011 11:12, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Well an unsaved object will have an id of nil. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 10 February 2011 09:37, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 10 February 2011 09:31, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 9 February 2011 11:12, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 10 February 2011 09:51, Peter Hickman <peterhickman386-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:>On 10 February 2011 09:37, Mauro >> Can''t I test if an object is saved or not in the database? > > Well an unsaved object will have an id of nil.or you can use the ".new_record?" method. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 10 February 2011 09:54, Michael Pavling <pavling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 10 February 2011 09:51, Peter Hickman <peterhickman386-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >>On 10 February 2011 09:37, Mauro >>> Can''t I test if an object is saved or not in the database? >> >> Well an unsaved object will have an id of nil. > > or you can use the ".new_record?" method. >I''ll try soon. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 10 February 2011 09:56, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 10 February 2011 09:54, Michael Pavling <pavling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> On 10 February 2011 09:51, Peter Hickman <peterhickman386-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >>>On 10 February 2011 09:37, Mauro >>>> Can''t I test if an object is saved or not in the database? >>> >>> Well an unsaved object will have an id of nil. >> >> or you can use the ".new_record?" method. >> > > I''ll try soon.It'' s not the solution. After I''ve saved @document and @delivery I go to show action where I have @delivery=Delivery.new and @document=Document.new, so new_record is always true. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 10 February 2011 16:02, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 10 February 2011 09:56, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> On 10 February 2011 09:54, Michael Pavling <pavling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> On 10 February 2011 09:51, Peter Hickman <peterhickman386-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >>>>On 10 February 2011 09:37, Mauro >>>>> Can''t I test if an object is saved or not in the database? >>>> >>>> Well an unsaved object will have an id of nil. >>> >>> or you can use the ".new_record?" method. >>> >> >> I''ll try soon. > > It'' s not the solution. > After I''ve saved @document and @delivery I go to show action where I > have @delivery=Delivery.new and @document=Document.new, so new_record > is always true.In the show action you should be finding the records in the database, not making new ones. Otherwise how are you going to show them? 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 10 February 2011 17:18, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 10 February 2011 16:02, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> On 10 February 2011 09:56, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> On 10 February 2011 09:54, Michael Pavling <pavling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>> On 10 February 2011 09:51, Peter Hickman <peterhickman386@googlemail.com> wrote: >>>>>On 10 February 2011 09:37, Mauro >>>>>> Can''t I test if an object is saved or not in the database? >>>>> >>>>> Well an unsaved object will have an id of nil. >>>> >>>> or you can use the ".new_record?" method. >>>> >>> >>> I''ll try soon. >> >> It'' s not the solution. >> After I''ve saved @document and @delivery I go to show action where I >> have @delivery=Delivery.new and @document=Document.new, so new_record >> is always true. > > In the show action you should be finding the records in the database, > not making new ones. Otherwise how are you going to show them?I show customer and in the same view I need a form to create a delivery and a document associated to that customer: This is customer show view: <p> <b><%= Customer.human_attribute_name("year") %>:</b> <%= @customer.year %> </p> <p> <b><%= Customer.human_attribute_name("code") %>:</b> <%= @customer.code %> </p> <p> <b><%= Customer.human_attribute_name("full_name") %>:</b> <%= @customer.full_name %> </p> <p> <b><%= Customer.human_attribute_name("birth_date") %>:</b> <% if @customer.birth_date %> <%= l @customer.birth_date %> <% else %> <%= @customer.birth_date %> <% end %> </p> <% content_for :delivery_form do %> <%= render ''deliveries/form'' %> <% end %> <% content_for :delivered do %> <p> <% if @delivery.valid? and @document.valid? %> <% for product in @customer.deliveries.last.products %> <%= product.description %><br /> <% end %> <% end %> </p> <p class="rightText"> <button id="print_button">stampa</button> </p> <% end %> The delivery_form partial is: <%= simple_form_for([@customer, @delivery]) do |f| %> <p> <%= f.input :delivered_at, :as => :hidden, :input_html => { :value => Date.today } %> </p> <p> <% for product in @products %> <%= check_box_tag ''delivery[product_ids][]'', product.id, @delivery.products.include?(product) %> <%= product.description %><br /> <% end %> <%= f.error :products%> </p><br /> <%= simple_fields_for @document do |doc| %> <p> <%= doc.label :doc_type %>:<br /> <%= doc.text_field :doc_type %> <%= doc.error :doc_type %> </p> <p> <%= doc.label :doc_number %>:<br /> <%= doc.text_field :doc_number %> <%= doc.error :doc_number %> </p> <p> <%= doc.label :issued_by %>:<br /> <%= doc.text_field :issued_by %> <%= doc.error :issued_by %> </p> <% end %> As you see I need @delivery and @document object and for that in the customer show action I''ve to do def show @customer = Customer.find(params[:id]) @delivery = Delivery.new @document = Document.new @products = Product.all end -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.