so basically what your saying is;
before filter: calc_remaining
def calc_renaming
#taken query here -- I forget what I did - not at my development
pc...
@remaining = @product.qty - @taken
end
Then call calc_renaming from the two methods I need to figure out what
remaining is.
Thanks,
Joe
On Saturday, March 4, 2017 at 3:18:11 AM UTC-5, Colin Law wrote:
>
> On 3 March 2017 at 22:39, Joe Guerra <[email protected] <javascript:>>
> wrote:
> > ok, I thought about that. Would it be ok to like set the instant
> variable
> > to a global and use that?
> >
> > $remaining = @remaining
> >
> > I tried that, and it seems to have worked. I not sure if it's the best
> > practice though.
>
> Definitely not. In addition to the fact that presumable @remaining is
> different for different products, and a request for a different
> product could come in between the two requests you are interested in
> (so the global would be set for the wrong product) consider the case
> where your app becomes popular enough to be distributed over multiple
> instances of the server. In that case the two requests might go to
> different servers so the global would not be setup for the second one.
> Also consider that when using something like nginx to run your
> production site that if it is not used for a while nginx may shutdown
> the app and restart it when the next request comes in. Again the
> global would not be set.
>
> I suggest following Hassan's advice.
>
> Colin
>
>
> >
> > On Friday, March 3, 2017 at 5:21:22 PM UTC-5, Colin Law wrote:
> >>
> >> On 3 March 2017 at 22:03, Joe Guerra <[email protected]> wrote:
> >> > Ok, how do I deal with that?
> >>
> >> You have to recalculate the variable in each method that you need it.
> >>
> >> Colin
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups
> > "Ruby on Rails: Talk" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an
> > email to [email protected] <javascript:>.
> > To post to this group, send email to [email protected]
> <javascript:>.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/rubyonrails-talk/46af96c5-857d-4742-894d-be66446bf1a0%40googlegroups.com.
>
>
> >
> > For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/6e912764-edf7-43b4-a243-2799d76607b1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.