Yes. You can do this.

But again. You should not instantiate a controller inside a Background job.


===================
*Alexandre Mondaini Calvão*

"*Nossa recompensa se encontra no esforço e não no resultado. Um esforço
total é uma vitória completa*." [Ghandi]

2015-04-07 15:25 GMT+10:00 amtest <vgrkrish...@gmail.com>:

> Thanks for the reply, here i meant that , can call the one method with
> *.delay, *
>
> class TestDelay < ActiveRecord::Base
>   def start_worker
>      tc = TestController.new
>
>      #Here calling that main function
>   end
> end
>
>
> this whole function works as a background job, that means 
> *TestDelay.delay.**start_worker,* is there any issues?
>
>
> On Tuesday, 7 April 2015 03:29:21 UTC+4, Alexandre Calvão wrote:
>>
>> This is totally the wrong way of doing this.
>>
>> You are breaking the MVC pattern.
>>
>> Neither the worker or the model should access the controller functions.
>>
>> You should put all the logic related to the delay job, inside the worker
>> or in separated classes.
>>
>> I like to have a worker classe inside the app folder /app/workers, and if
>> a need more complex objects I put them inside the /lib folder
>>
>>
>> ===================
>> *Alexandre Mondaini Calvão*
>>
>> "*Nossa recompensa se encontra no esforço e não no resultado. Um esforço
>> total é uma vitória completa*." [Ghandi]
>>
>> 2015-04-07 3:22 GMT+10:00 amruby <vgrkr...@gmail.com>:
>>
>>>
>>>    I have one function, that have been working in *delayed job*.
>>>
>>> class TestDelay < ActiveRecord::Base
>>>   def start_worker
>>>      tc = TestController.new
>>>
>>>      #Here calling that main function
>>>   endend
>>>
>>>
>>> also i have one other class
>>>
>>> class TestController < ApplicationController
>>>   before_filter :filter1, :filter2
>>>
>>>   def follow_function
>>>     #Doing the main portion
>>>   end
>>>
>>>   protected
>>>   def filter1
>>>   end
>>>
>>>   def filter2
>>>   endend
>>>
>>>
>>> In the class *TestController* has two filters, that will work on every
>>> action, there setting the instance variables on that filters, and using
>>> that in my *follow_function*. So the issues are when i am trying to
>>> call the follow_function from the delayed job method *start_worker*, i
>>> need to set the instance variables in that filters, this is the exact way
>>> to do this?
>>>
>>> so what i tried something like that i put one function in
>>> *TestController* class like
>>>
>>> def init_variables(names)
>>>   #filter1(names)
>>>   #filter2(names)end
>>> class TestDelay < ActiveRecord::Base
>>>   def start_worker
>>>      class_name.init_variables(params)
>>>   endend
>>>
>>> and i tried to passing arguments in before_filter, but its totally
>>> failed and getting weird. Is this the correct way to do this?
>>>
>>> --
>>> 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-ta...@googlegroups.com.
>>> To post to this group, send email to rubyonra...@googlegroups.com.
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/rubyonrails-talk/70d3a481-a90b-4632-8786-
>>> da2c1e24fe9f%40googlegroups.com
>>> <https://groups.google.com/d/msgid/rubyonrails-talk/70d3a481-a90b-4632-8786-da2c1e24fe9f%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> 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 rubyonrails-talk+unsubscr...@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/dba06236-8f14-4d27-8368-2198dcfec46e%40googlegroups.com
> <https://groups.google.com/d/msgid/rubyonrails-talk/dba06236-8f14-4d27-8368-2198dcfec46e%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> 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 rubyonrails-talk+unsubscr...@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/CA%2BaBw4Q7Pk61Dw5ismpoRkVJ101m%2Be%3DTvO%3DPLr6P0pfe4Binuw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to