Controller Delivery: 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] = "Consegna effettuata." respond_with(@customer) else @products = Product.all render ''customers/show'', :layout => ''delivery'' end end When @delivery and @document are saved it redirects to customer show. I do customer show also at application startup, after a search. How can I know if the show is a redirect from Delivery create? -- 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 18 February 2011 11:28, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Controller Delivery: > > 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 > -Ym6Zj+ZQYSqzOeKtxYPyNA@public.gmane.org! > -DL+rna6QvqSzOeKtxYPyNA@public.gmane.org! > end > flash[:success] = "Consegna effettuata." > respond_with(@customer) > else > @products = Product.all > render ''customers/show'', :layout => ''delivery'' > end > end > > When @delivery and @document are saved it redirects to customer show. > I do customer show also at application startup, after a search. > How can I know if the show is a redirect from Delivery create?You can always just set an @variable in the create action and test it in the view. Don''t call it ''@coming_from_create'' though, call it something that indicates what is required of the view. If you call it @coming_from_create then it is almost guaranteed that a some point you will want to set in some other circumstance also, and then the name will not make sense. 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.
You can use request.env[''HTTP_REFERER''] On Fri, Feb 18, 2011 at 7:49 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 18 February 2011 11:28, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Controller Delivery: > > > > 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] = "Consegna effettuata." > > respond_with(@customer) > > else > > @products = Product.all > > render ''customers/show'', :layout => ''delivery'' > > end > > end > > > > When @delivery and @document are saved it redirects to customer show. > > I do customer show also at application startup, after a search. > > How can I know if the show is a redirect from Delivery create? > > You can always just set an @variable in the create action and test it > in the view. Don''t call it ''@coming_from_create'' though, call it > something that indicates what is required of the view. If you call it > @coming_from_create then it is almost guaranteed that a some point you > will want to set in some other circumstance also, and then the name > will not make sense. > > 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. > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.com -- 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.
if request.env[''HTTP_REFERER''] == new_costumer_url -- 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 18 February 2011 11:53, Jim Ruther Nill <jvnill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You can use request.env[''HTTP_REFERER'']I would advise against that method. The view should not be making decisions based on where it came from, it should be displaying what it is told to display. If a particular action (create in this case) requires something particular of a view then the action should tell the view what to do by setting an @variable. The view should not be saying ''I see that I came from the create action therefore I will display this'', it should be saying ''I see that this variable contains this data so I will display the data as requested''. @Mauro, what is the difference you wish to see in the view based on where it came from? Colin> > > On Fri, Feb 18, 2011 at 7:49 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> >> On 18 February 2011 11:28, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > Controller Delivery: >> > >> > 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 >> > -Ym6Zj+ZQYSqzOeKtxYPyNA@public.gmane.org! >> > -DL+rna6QvqSzOeKtxYPyNA@public.gmane.org! >> > end >> > flash[:success] = "Consegna effettuata." >> > respond_with(@customer) >> > else >> > @products = Product.all >> > render ''customers/show'', :layout => ''delivery'' >> > end >> > end >> > >> > When @delivery and @document are saved it redirects to customer show. >> > I do customer show also at application startup, after a search. >> > How can I know if the show is a redirect from Delivery create? >> >> You can always just set an @variable in the create action and test it >> in the view. Don''t call it ''@coming_from_create'' though, call it >> something that indicates what is required of the view. If you call it >> @coming_from_create then it is almost guaranteed that a some point you >> will want to set in some other circumstance also, and then the name >> will not make sense. >> >> 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. >> > > > > -- > ------------------------------------------------------------- > visit my blog at http://jimlabs.heroku.com > > -- > 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. >-- 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 18 February 2011 13:02, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 18 February 2011 11:53, Jim Ruther Nill <jvnill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> You can use request.env[''HTTP_REFERER''] > > I would advise against that method. The view should not be making > decisions based on where it came from, it should be displaying what it > is told to display. If a particular action (create in this case) > requires something particular of a view then the action should tell > the view what to do by setting an @variable. The view should not be > saying ''I see that I came from the create action therefore I will > display this'', it should be saying ''I see that this variable contains > this data so I will display the data as requested''. > > @Mauro, what is the difference you wish to see in the view based on > where it came from?If the view is a redirect from Delivery create I want to see the message "create success" and a button "print" to print something. I the same view comes from the search customers action I want to see the message "already delivered" if customer.deliveries.count > 0 and a link "want to continue?" -- 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.
Store this info in flash flash[:success] = "Consegna effettuata." flash[:redirect_from] = :something respond_with(@customer) Then you can read it later. Robert Pankowecki -- 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 Fri, Feb 18, 2011 at 9:02 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 18 February 2011 11:53, Jim Ruther Nill <jvnill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > You can use request.env[''HTTP_REFERER''] > > I would advise against that method. The view should not be making > decisions based on where it came from, it should be displaying what it > is told to display. If a particular action (create in this case) > requires something particular of a view then the action should tell > the view what to do by setting an @variable. The view should not be > saying ''I see that I came from the create action therefore I will > display this'', it should be saying ''I see that this variable contains > this data so I will display the data as requested''. >then use that in the show controller. @something = request.env[''HTTP_REFERER''] == show_url ? option1 : option2 then use @something in the view. -- 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 18 February 2011 14:39, Jim Ruther Nill <jvnill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On Fri, Feb 18, 2011 at 9:02 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> >> On 18 February 2011 11:53, Jim Ruther Nill <jvnill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > You can use request.env[''HTTP_REFERER''] >> >> I would advise against that method. The view should not be making >> decisions based on where it came from, it should be displaying what it >> is told to display. If a particular action (create in this case) >> requires something particular of a view then the action should tell >> the view what to do by setting an @variable. The view should not be >> saying ''I see that I came from the create action therefore I will >> display this'', it should be saying ''I see that this variable contains >> this data so I will display the data as requested''.I think Colin is right and the solution is more simple than I thought. I check flash[:success] if it is nil or not. -- 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.