Ruby on Rails Saturday, March 4, 2017

On 4 March 2017 at 18:10, Joe Guerra <JGuerra@jginfosys.com> wrote:
> 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.

You won't need to call it explicitly in the methods, that is what
before_filter does. If you only need it in those two methods then
either specify that in the before filter (look at the docs for how to
do that), or don't use before filter just call it in the methods.
However if @taken is also a query on product then define a method in
product called, possibly, remaining and then in your methods just do
@remaining = @product.remaining

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 rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLs7riaChWmwXabEtoPmh8b7aac1ntJGhT-_jtDGvPtT7g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment