Call a controller from the rake file

How to call a controller from the rake file, Just i have tried to
create
a controller object in rake, and call the method, but i didn’t get
that…
also how to link the helper class with the rake?

On 25 January 2012 05:39, amvis [email protected] wrote:

How to call a controller from the rake file, Just i have tried to create a
controller object in rake, and call the method, but i didn’t get that…
also how to link the helper class with the rake?

I don’t believe it makes sense to call controller methods from a rake
task. Put the bits you want to call in a model and you can call them.
Similarly to call view helper models does not make sense. There is
no view so what good are view helpers? Put the code in models or in
lib.

Colin

can i use like this…

myrake file

task :my_task => [:environment] do
rd=MofobirakesController.new
rd.index
end

Controller file
*
*
*
*
class MofobirakesController < ApplicationController
def index
puts “hai rails3”
end
end

what is the difference in that way to do in controller and in model…?

On 25 January 2012 08:36, amvis [email protected] wrote:

classMofobirakesController< ApplicationController
def index
puts “hai rails3”
end
end

what is the difference in that way to do in controller and in model…?

The difference is that controller actions are intended to be run in
response to http requests. To try and run one as part of a rake
action does not make logical sense.

You ask at the top whether it would work, I have no idea whether it
would work or not and it is irrelevant because there is no sense in
doing it. If you have code that is common between a controller action
and a rake task then the code should not be in a controller action.
Move it to a model or into lib and call it from the controller and the
rake task.
What does the code that you want to call do?

Colin

For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


gplus.to/clanlaw

On 25 January 2012 11:55, amvis [email protected] wrote:

Basically i need to write one cron job for running the rake file from
which, i’ll call one class, that have one query which will take data from
some tables and will put into another tables. This is my objective. But now
created one .rb file in lib/ directory and created one .rake in task/
directory. Also call the .rb file from the rake. This is now working…

Is it enough for my operation?

I don’t understand, you say “This is now working” but then ask if it is
enough.

Colin

Basically i need to write one cron job for running the rake file from
which, i’ll call one class, that have one query which will take data
from
some tables and will put into another tables. This is my objective. But
now created one .rb file in lib/ directory and created one .rake in
task/
directory. Also call the .rb file from the rake.
This is now
working…

Is it enough for my operation?

Thank you
vishnu